dw-spider/options/cfg.go
timerzz 70e1f4c6bc
Some checks failed
Build image / build (push) Has been cancelled
feat 初始化
2024-07-29 21:32:27 +08:00

29 lines
525 B
Go

package options
import (
"os"
"gitea.timerzz.com/kedaya_haitao/common/pkg/database"
dw_sdk "gitea.timerzz.com/kedaya_haitao/dw-sdk"
"gopkg.in/yaml.v3"
)
type Config struct {
DB database.DBOption `yaml:"db"`
Dw dw_sdk.Config `yaml:"dw"`
}
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)
}