us-coach-spider/pkg/options/init.go
timerzz 8934e23bd8
All checks were successful
Build image / build (push) Successful in 1m34s
feat 配置写入数据库
2024-05-14 16:17:04 +08:00

28 lines
536 B
Go

package options
import (
"gitea.timerzz.com/kedaya_haitao/common/pkg/database"
"gitea.timerzz.com/kedaya_haitao/common/pkg/proxy"
"gopkg.in/yaml.v3"
"os"
)
type Config struct {
DB database.DBOption `yaml:"db"`
Proxy proxy.Option `yaml:"proxy"`
}
func LoadConfig() (*Config, error) {
cfgPath := os.Getenv("CONFIG_PATH")
if cfgPath == "" {
cfgPath = "/data/cfg.yaml"
}
var opt Config
f, err := os.Open(cfgPath)
if err != nil {
return nil, err
}
defer f.Close()
return &opt, yaml.NewDecoder(f).Decode(&opt)
}