37 lines
568 B
Go
37 lines
568 B
Go
|
package config
|
||
|
|
||
|
import (
|
||
|
"os"
|
||
|
|
||
|
"gopkg.in/yaml.v2"
|
||
|
)
|
||
|
|
||
|
var CF = new(Config)
|
||
|
|
||
|
type Config struct {
|
||
|
DocDB struct {
|
||
|
Host string
|
||
|
Port string
|
||
|
User string
|
||
|
Password string
|
||
|
DbName string
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func init() {
|
||
|
var configFilePath string
|
||
|
if os.Getenv("MODE_ENV") != "" {
|
||
|
configFilePath = "/conf/config.yaml"
|
||
|
} else {
|
||
|
configFilePath = "/conf/" + os.Getenv("MODE_ENV") + "/config.yaml"
|
||
|
}
|
||
|
fi, err := os.Open(configFilePath)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
defer fi.Close()
|
||
|
if err := yaml.NewDecoder(fi).Decode(&CF); err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
}
|