dw-sdk/config.go

43 lines
913 B
Go

package dw_sdk
import (
"os"
"gopkg.in/yaml.v3"
)
type Config struct {
Public PublicConfig `json:"public" yaml:"public"`
Proxy *ProxyConfig `json:"proxy,omitempty" yaml:"proxy,omitempty"`
}
type PublicConfig struct {
Key string `json:"key" yaml:"key"`
Secret string `json:"secret" yaml:"secret"`
Env string `json:"env" yaml:"env"`
}
type ProxyConfig struct {
Host string `json:"host" yaml:"host"`
Port string `json:"port" yaml:"port"`
User string `json:"user" yaml:"user"`
Pass string `json:"pass" yaml:"pass"`
}
const (
// 默认的数据库配置文件路径
DefaultConfigPath = "/cfg/dw.yaml"
// 数据库配置文件路径环境变量
ConfigPathEnvKey = "DW_CONFIG_PATH"
)
func LoadDWConfig(path string) (*Config, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
var opt Config
return &opt, yaml.NewDecoder(f).Decode(&opt)
}