micro-document/config/config.go

40 lines
861 B
Go
Raw Normal View History

2025-06-10 03:10:19 +00:00
package config
import (
2025-06-11 02:11:17 +00:00
"fmt"
2025-06-10 03:10:19 +00:00
"os"
2025-06-11 02:11:17 +00:00
"dubbo.apache.org/dubbo-go/v3/common/constant"
2025-06-10 03:10:19 +00:00
"gopkg.in/yaml.v2"
)
var CF = new(Config)
type Config struct {
DocDB struct {
2025-06-11 02:11:17 +00:00
Host string `yaml:"host"`
User string `yaml:"user"`
Password string `yaml:"password"`
DbName string `yaml:"dbName"`
} `yaml:"docDb"`
2025-06-10 03:10:19 +00:00
}
2025-06-11 02:11:17 +00:00
func ConfigInit() {
2025-06-10 03:10:19 +00:00
var configFilePath string
2025-06-11 02:11:17 +00:00
if os.Getenv("MODE_ENV") == "" {
configFilePath = "../conf/config.yaml"
os.Setenv(constant.ConfigFileEnvKey, "../conf/dubbogo.yaml")
2025-06-10 03:10:19 +00:00
} else {
2025-06-11 02:11:17 +00:00
configFilePath = "./conf/" + os.Getenv("MODE_ENV") + "/config.yaml"
os.Setenv(constant.ConfigFileEnvKey, fmt.Sprintf("./conf/%s/%s", os.Getenv("MODE_ENV"), "dubbogo.yaml"))
2025-06-10 03:10:19 +00:00
}
fi, err := os.Open(configFilePath)
if err != nil {
panic(err)
}
defer fi.Close()
if err := yaml.NewDecoder(fi).Decode(&CF); err != nil {
panic(err)
}
}