package config
|
|
import (
|
"log"
|
|
"github.com/spf13/viper"
|
)
|
|
type server struct {
|
Runmode string `mapstructure: "runmode"`
|
JwtSecret string `mapstructure: "jwtSecret"`
|
JwtExpire string `mapstructure: "jwtExpire"`
|
Url string `mapstructure: "url"`
|
ImageUrl string `mapstructure: "imageUrl"`
|
PublicDomain string `mapstructure: "publicDomain"`
|
NetworkAdapter string `mapstructure: "networkAdapter"`
|
}
|
|
var Server = &server{}
|
|
type weedfs struct {
|
Ip string `mapstructure: "ip"`
|
UploadPort int `mapstructure: "uploadport"`
|
VisitPort int `mapstructure: "visitport"`
|
}
|
|
var WeedFs = &weedfs{}
|
|
type redis struct {
|
Host string `mapstructure:"host"`
|
Port int `mapstructure:"port"`
|
Password string `mapstructure:"password`
|
DBNum int `mapstructure:"db"`
|
}
|
|
var RedisConf = &redis{}
|
|
type database struct {
|
Drive string `mapstructure:"drive"`
|
Name string `mapstructure:"name"`
|
FilePath string `mapstructure:"filepath"`
|
}
|
|
// wp add es 索引 以及 IP port
|
type esinfo struct {
|
Masterip string `mapstructure:"masterip"`
|
Httpport string `mapstructure:"httpport"`
|
EsIndex esindexlist `mapstructure:"index"`
|
}
|
|
type esindexlist struct {
|
VideoPersons index `mapstructure:"videopersons"`
|
DbTables index `mapstructure:"dbtables"`
|
Dbtablepersons index `mapstructure:"dbtablepersons"`
|
Personaction index `mapstructure:"personaction"`
|
}
|
|
type index struct {
|
IndexName string `mapstructure:"index"`
|
IndexType string `mapstructure:"type"`
|
}
|
|
var EsInfo = &esinfo{}
|
|
var DBconf = &database{}
|
|
type dbpersoncompare struct {
|
Url string `mapstructure:"url"`
|
}
|
|
type espersoncompare struct {
|
Url []string `mapstructure:"url"`
|
}
|
|
var DbPersonCompInfo = &dbpersoncompare{}
|
|
var EsCompServerInfo = &espersoncompare{}
|
|
|
// Init is an exported method that takes the environment starts the viper
|
// (external lib) and returns the configuration struct.
|
func Init(env string) {
|
var err error
|
viper.SetConfigType("yaml")
|
viper.SetConfigName(env)
|
viper.AddConfigPath("../config/")
|
viper.AddConfigPath("config/")
|
err = viper.ReadInConfig()
|
if err != nil {
|
log.Fatal("error on parsing configuration file")
|
}
|
viper.UnmarshalKey("es", EsInfo)
|
viper.UnmarshalKey("server", Server)
|
viper.UnmarshalKey("redis", RedisConf)
|
viper.UnmarshalKey("database", DBconf)
|
viper.UnmarshalKey("weedfs", WeedFs)
|
viper.UnmarshalKey("dbpersoncompare",DbPersonCompInfo)
|
viper.UnmarshalKey("espersoncompare", EsCompServerInfo)
|
}
|