54 lines
930 B
Go
54 lines
930 B
Go
package start
|
|
|
|
import (
|
|
"busniess-user-center/config"
|
|
"busniess-user-center/pkg/db"
|
|
"busniess-user-center/pkg/log"
|
|
"busniess-user-center/pkg/redis"
|
|
"fmt"
|
|
|
|
"github.com/samber/do"
|
|
)
|
|
|
|
const (
|
|
defaultConfigPath = "./conf.yaml"
|
|
)
|
|
|
|
func Setup() {
|
|
// 读取配置
|
|
conf, err := loadConf()
|
|
if err != nil {
|
|
panic(err.Error())
|
|
}
|
|
|
|
do.ProvideValue(nil, conf)
|
|
|
|
// 根加配置初始化日志zap
|
|
logger, err := log.NewSugarLogger(conf.Log)
|
|
if err != nil {
|
|
panic(err.Error())
|
|
}
|
|
|
|
do.ProvideValue(nil, logger)
|
|
|
|
redis, err := redis.NewRedis(&conf.Redis)
|
|
if err != nil {
|
|
panic(fmt.Sprintf("redis init fail:%s", err.Error()))
|
|
}
|
|
|
|
do.ProvideValue(nil, redis)
|
|
|
|
// 根据配置启动mysql
|
|
db, err := db.InitDB(logger, conf.Mysql)
|
|
if err != nil {
|
|
panic(err.Error())
|
|
}
|
|
|
|
do.ProvideValue(nil, db)
|
|
}
|
|
|
|
// todo 配置中心拉去配置
|
|
func loadConf() (*config.AppConfig, error) {
|
|
return config.LoadConfig(defaultConfigPath)
|
|
}
|