watcher/pkg/options/init.go

26 lines
417 B
Go
Raw Normal View History

2024-04-10 17:36:56 +08:00
package options
import (
"gopkg.in/yaml.v3"
"os"
)
type Config struct {
DB DBOption `yaml:"db"`
Proxy ProxyOption `yaml:"proxy"`
}
func LoadConfig() (*Config, error) {
cfgPath := os.Getenv("CONFIG_PATH")
if cfgPath == "" {
cfgPath = "/data/cfg.yaml"
}
2024-04-10 17:36:56 +08:00
var opt Config
f, err := os.Open(cfgPath)
2024-04-10 17:36:56 +08:00
if err != nil {
return nil, err
}
defer f.Close()
return &opt, yaml.NewDecoder(f).Decode(&opt)
}