30 lines
640 B
Go
30 lines
640 B
Go
package options
|
|
|
|
import (
|
|
"gitea.timerzz.com/kedaya_haitao/coach-spider/product"
|
|
"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"`
|
|
Product product.Option `yaml:"product"`
|
|
}
|
|
|
|
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)
|
|
}
|