cn-coach-spider/pkg/options/init.go
timerzz d4a39a0e45
Some checks failed
Build image / build (push) Failing after 34s
feat init
2024-06-14 16:36:33 +08:00

28 lines
501 B
Go

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