Commit 307b8f3c by zhengqiuyun86

初始化

parent 339e1d59
......@@ -8,29 +8,25 @@ type Config struct {
LogResponseLength int
LogShowSql bool
//RedisAddr Redis conf
RedisAddr string
RedisPwd string
RedisDb int
RedisConf RedisConf
//EsServerHttp
EsServerHttp string
EsConf EsConf
//mysqlrym
MysqlConf MysqlConf
}
func BaseConfig(conf Config) {
ServerName = conf.ServerName
Env = conf.Env
LogLevel = conf.LogLevel
LogColorful = conf.LogColorful
LogResponseLength = conf.LogResponseLength
LogShowSql = conf.LogShowSql
RedisAddr = conf.RedisAddr
RedisPwd = conf.RedisPwd
RedisDb = conf.RedisDb
ServerName = conf.ServerName
Env = conf.Env
EsServerHttp = conf.EsServerHttp
Es = conf.EsConf
Redis = conf.RedisConf
MySql = conf.MysqlConf
}
......@@ -46,12 +42,21 @@ var LogResponseLength = 10
var LogShowSql = true
//Redis conf
var RedisAddr = ""
var RedisPwd = ""
var RedisDb = 0
type RedisConf struct {
RedisAddr string
RedisPwd string
RedisDb int
}
var Redis = RedisConf{}
//ES conf
var EsServerHttp = ""
type EsConf struct {
ServerHost string
ServerPort int
}
var Es = EsConf{}
//Mysql conf
type MysqlConf struct {
......
......@@ -18,7 +18,7 @@ var Client *elastic.Client
//初始化
func init() {
host := conf.EsServerHttp
host := fmt.Sprintf("http://%s:%d", conf.Es.ServerHost, conf.Es.ServerPort)
var err error
errorLog := _log.New(os.Stdout, "APP", _log.LstdFlags)
Client, err = elastic.NewClient(elastic.SetErrorLog(errorLog), elastic.SetURL(host))
......
......@@ -17,9 +17,9 @@ var redisClient *redis.Client
func init() {
redisClient = redis.NewClient(&redis.Options{
Addr: conf.RedisAddr,
Password: conf.RedisPwd,
DB: conf.RedisDb, // redis一共16个库,指定其中一个库即可
Addr: conf.Redis.RedisAddr,
Password: conf.Redis.RedisPwd,
DB: conf.Redis.RedisDb, // redis一共16个库,指定其中一个库即可
})
_, err := redisClient.Ping().Result()
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