2024-04-10 17:36:56 +08:00
|
|
|
package options
|
|
|
|
|
|
|
|
import (
|
2024-05-13 20:18:13 +08:00
|
|
|
"gitea.timerzz.com/kedaya_haitao/common/pkg/database"
|
|
|
|
"gitea.timerzz.com/kedaya_haitao/common/pkg/proxy"
|
2024-04-10 17:36:56 +08:00
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2024-05-13 20:18:13 +08:00
|
|
|
DB database.DBOption `yaml:"db"`
|
|
|
|
Proxy proxy.Option `yaml:"proxy"`
|
2024-04-10 17:36:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func LoadConfig() (*Config, error) {
|
2024-04-12 14:51:51 +08:00
|
|
|
cfgPath := os.Getenv("CONFIG_PATH")
|
|
|
|
if cfgPath == "" {
|
|
|
|
cfgPath = "/data/cfg.yaml"
|
|
|
|
}
|
2024-04-10 17:36:56 +08:00
|
|
|
var opt Config
|
2024-04-12 14:51:51 +08:00
|
|
|
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)
|
|
|
|
}
|