2024-07-24 10:43:43 +08:00
|
|
|
package dw_sdk
|
|
|
|
|
2024-09-02 20:16:06 +08:00
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
)
|
|
|
|
|
2024-07-24 10:43:43 +08:00
|
|
|
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"`
|
|
|
|
}
|
2024-09-02 20:16:06 +08:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|