config.go 1.31 KB
Newer Older
贾浩@五瓣科技's avatar
贾浩@五瓣科技 committed
1 2 3 4 5 6 7 8 9
package config

import (
	"flag"

	"github.com/BurntSushi/toml"
)

type Config struct {
贾浩@五瓣科技's avatar
贾浩@五瓣科技 committed
10 11 12 13
	Debug       bool              `toml:"debug"`
	PGSQL       PGSQLConfig       `toml:"pgsql"`
	Server      ServerConfig      `toml:"server"`
	TGTask      TGTaskConfig      `toml:"tg_task"`
贾浩@五瓣科技's avatar
贾浩@五瓣科技 committed
14
	TwitterTask TwitterTaskConfig `toml:"twitter_task"`
贾浩@五瓣科技's avatar
贾浩@五瓣科技 committed
15
	Supabase    SupabaseConfig    `tomo:"supabase"`
贾浩@五瓣科技's avatar
贾浩@五瓣科技 committed
16 17 18
}

type SupabaseConfig struct {
贾浩@五瓣科技's avatar
贾浩@五瓣科技 committed
19 20 21
	AuthURL   string `toml:"auth_url"`
	APIKey    string `toml:"api_key"`
	JWTSecret string `toml:"jwt_secret"`
贾浩@五瓣科技's avatar
贾浩@五瓣科技 committed
22 23
}

贾浩@五瓣科技's avatar
贾浩@五瓣科技 committed
24
type PGSQLConfig struct {
贾浩@五瓣科技's avatar
贾浩@五瓣科技 committed
25 26 27 28 29 30 31 32
	Host        string `toml:"host"`
	Port        int    `toml:"port"`
	User        string `toml:"user"`
	Password    string `toml:"password"`
	Database    string `toml:"database"`
	MaxConn     int    `toml:"max_conn"`
	MaxIdleConn int    `toml:"max_idle_conn"`
	EnableLog   bool   `toml:"enable_log"`
贾浩@五瓣科技's avatar
贾浩@五瓣科技 committed
33
	CertFile    string `toml:"cert_file"`
贾浩@五瓣科技's avatar
贾浩@五瓣科技 committed
34 35
}

贾浩@五瓣科技's avatar
贾浩@五瓣科技 committed
36
type TGTaskConfig struct {
37 38
	URL      string `toml:"url"`
	BOTToken string `toml:"bot_token"`
贾浩@五瓣科技's avatar
贾浩@五瓣科技 committed
39 40
}

贾浩@五瓣科技's avatar
贾浩@五瓣科技 committed
41
type TwitterTaskConfig struct {
42 43
	URL        string `toml:"url"`
	PassFollow bool   `toml:"pass_follow"`
贾浩@五瓣科技's avatar
贾浩@五瓣科技 committed
44 45
}

贾浩@五瓣科技's avatar
贾浩@五瓣科技 committed
46 47
type ServerConfig struct {
	Listen string `toml:"listen"`
贾浩@五瓣科技's avatar
贾浩@五瓣科技 committed
48 49 50 51 52 53 54 55 56
}

var confPath = flag.String("c", "config.toml", "config file path")

func New() (config *Config, err error) {
	config = new(Config)
	_, err = toml.DecodeFile(*confPath, config)
	return
}