2021-03-24 17:18:39 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
2021-04-16 15:10:07 +08:00
|
|
|
"mayfly-go/base/global"
|
2021-03-24 17:18:39 +08:00
|
|
|
"mayfly-go/base/rediscli"
|
2021-04-16 15:10:07 +08:00
|
|
|
"mayfly-go/mock-server/initialize"
|
2021-03-24 17:18:39 +08:00
|
|
|
_ "mayfly-go/mock-server/routers"
|
2021-04-16 15:10:07 +08:00
|
|
|
"mayfly-go/mock-server/starter"
|
2021-03-24 17:18:39 +08:00
|
|
|
|
|
|
|
|
"github.com/go-redis/redis"
|
|
|
|
|
// _ "github.com/go-sql-driver/mysql"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
// 设置redis客户端
|
2021-04-16 15:10:07 +08:00
|
|
|
redisConf := global.Config.Redis
|
2021-03-24 17:18:39 +08:00
|
|
|
rdb := redis.NewClient(&redis.Options{
|
2021-04-16 15:10:07 +08:00
|
|
|
Addr: fmt.Sprintf("%s:%d", redisConf.Host, redisConf.Port),
|
|
|
|
|
Password: redisConf.Password, // no password set
|
|
|
|
|
DB: redisConf.Db, // use default DB
|
2021-03-24 17:18:39 +08:00
|
|
|
})
|
2021-04-16 15:10:07 +08:00
|
|
|
// 测试连接
|
|
|
|
|
_, e := rdb.Ping().Result()
|
|
|
|
|
if e != nil {
|
|
|
|
|
global.Log.Panic(fmt.Sprintf("连接redis失败! [%s:%d]", redisConf.Host, redisConf.Port))
|
|
|
|
|
}
|
2021-03-24 17:18:39 +08:00
|
|
|
rediscli.SetCli(rdb)
|
|
|
|
|
|
2021-04-16 15:10:07 +08:00
|
|
|
db := initialize.GormMysql()
|
|
|
|
|
if db == nil {
|
|
|
|
|
global.Log.Panic("mysql连接失败")
|
|
|
|
|
} else {
|
|
|
|
|
global.Db = db
|
2021-03-24 17:18:39 +08:00
|
|
|
}
|
2021-04-16 15:10:07 +08:00
|
|
|
|
|
|
|
|
starter.RunServer()
|
2021-03-24 17:18:39 +08:00
|
|
|
}
|