package config
|
|
|
|
import (
|
|
"LAPP_AS/utils"
|
|
"fmt"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
var AppConfig Config
|
|
|
|
type Config struct {
|
|
*DB `mapstructure:"db"`
|
|
*Mongo `mapstructure:"mongo"`
|
|
*App `mapstructure:"app"`
|
|
*ETCD `mapstructure:"etcd"`
|
|
}
|
|
|
|
type DB struct {
|
|
Host string `yaml:"host"`
|
|
Port int `yaml:"port"`
|
|
User string `yaml:"user"`
|
|
Password string `yaml:"password"`
|
|
Database string `yaml:"database"`
|
|
}
|
|
|
|
type Mongo struct {
|
|
Host string `yaml:"host"`
|
|
Port int `yaml:"port"`
|
|
DataDB string `yaml:"datadb"`
|
|
LogDB string `yaml:"logdb"`
|
|
}
|
|
|
|
type App struct {
|
|
Port int `yaml:"port"`
|
|
TaskNums int `yaml:"tasknums"`
|
|
ErrNums int `yaml:"errnums"`
|
|
ShellPath string `yaml:"shellpath"`
|
|
LocalAddr string `yaml:"localaddr"`
|
|
Mod string `yaml:"mod"`
|
|
Name string `yaml:"name"`
|
|
UseETCD bool `yaml:"useetcd"`
|
|
}
|
|
|
|
type ETCD struct {
|
|
Addrs []string `yaml:"addrs"`
|
|
Timeout int `yaml:"timeout"`
|
|
LockLease int64 `yaml:"locklease"`
|
|
ServiceLease int64 `yaml:"servicelease"`
|
|
}
|
|
|
|
func InitConfig() (err error) {
|
|
baseDir, err := utils.GetCurrentPath("conf")
|
|
fmt.Println("conf:", baseDir)
|
|
if err != nil {
|
|
return
|
|
}
|
|
viper.SetConfigName("app_config")
|
|
viper.SetConfigType("yaml")
|
|
viper.AddConfigPath(baseDir)
|
|
|
|
if err = viper.ReadInConfig(); err != nil {
|
|
return
|
|
}
|
|
if err = viper.Unmarshal(&AppConfig); err != nil {
|
|
return
|
|
}
|
|
return nil
|
|
}
|