Commit 307b8f3c by zhengqiuyun86

初始化

parent 339e1d59
...@@ -8,29 +8,25 @@ type Config struct { ...@@ -8,29 +8,25 @@ type Config struct {
LogResponseLength int LogResponseLength int
LogShowSql bool LogShowSql bool
//RedisAddr Redis conf RedisConf RedisConf
RedisAddr string
RedisPwd string
RedisDb int
//EsServerHttp EsConf EsConf
EsServerHttp string
//mysqlrym
MysqlConf MysqlConf MysqlConf MysqlConf
} }
func BaseConfig(conf Config) { func BaseConfig(conf Config) {
ServerName = conf.ServerName
Env = conf.Env
LogLevel = conf.LogLevel LogLevel = conf.LogLevel
LogColorful = conf.LogColorful LogColorful = conf.LogColorful
LogResponseLength = conf.LogResponseLength LogResponseLength = conf.LogResponseLength
LogShowSql = conf.LogShowSql LogShowSql = conf.LogShowSql
RedisAddr = conf.RedisAddr
RedisPwd = conf.RedisPwd Es = conf.EsConf
RedisDb = conf.RedisDb
ServerName = conf.ServerName Redis = conf.RedisConf
Env = conf.Env
EsServerHttp = conf.EsServerHttp
MySql = conf.MysqlConf MySql = conf.MysqlConf
} }
...@@ -46,12 +42,21 @@ var LogResponseLength = 10 ...@@ -46,12 +42,21 @@ var LogResponseLength = 10
var LogShowSql = true var LogShowSql = true
//Redis conf //Redis conf
var RedisAddr = "" type RedisConf struct {
var RedisPwd = "" RedisAddr string
var RedisDb = 0 RedisPwd string
RedisDb int
}
var Redis = RedisConf{}
//ES conf //ES conf
var EsServerHttp = "" type EsConf struct {
ServerHost string
ServerPort int
}
var Es = EsConf{}
//Mysql conf //Mysql conf
type MysqlConf struct { type MysqlConf struct {
......
...@@ -18,7 +18,7 @@ var Client *elastic.Client ...@@ -18,7 +18,7 @@ var Client *elastic.Client
//初始化 //初始化
func init() { func init() {
host := conf.EsServerHttp host := fmt.Sprintf("http://%s:%d", conf.Es.ServerHost, conf.Es.ServerPort)
var err error var err error
errorLog := _log.New(os.Stdout, "APP", _log.LstdFlags) errorLog := _log.New(os.Stdout, "APP", _log.LstdFlags)
Client, err = elastic.NewClient(elastic.SetErrorLog(errorLog), elastic.SetURL(host)) Client, err = elastic.NewClient(elastic.SetErrorLog(errorLog), elastic.SetURL(host))
......
...@@ -17,9 +17,9 @@ var redisClient *redis.Client ...@@ -17,9 +17,9 @@ var redisClient *redis.Client
func init() { func init() {
redisClient = redis.NewClient(&redis.Options{ redisClient = redis.NewClient(&redis.Options{
Addr: conf.RedisAddr, Addr: conf.Redis.RedisAddr,
Password: conf.RedisPwd, Password: conf.Redis.RedisPwd,
DB: conf.RedisDb, // redis一共16个库,指定其中一个库即可 DB: conf.Redis.RedisDb, // redis一共16个库,指定其中一个库即可
}) })
_, err := redisClient.Ping().Result() _, err := redisClient.Ping().Result()
if err != nil { if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment