package main import ( "fieldproject_common/config" "fieldproject_common/db" "fmt" "go.uber.org/zap" "os" "utils/log" ) // InitDb @Description // @Author J 2022/7/26 15:20 func InitDb() error { var ( err error ) dbcfg := config.Conf.DB err = db.NewDb(db.Drivename(dbcfg.Drivename), db.Dsn(dbcfg.Dsn), db.MaxIdleConnection(dbcfg.MaxIdle), db.MaxOpenConnection(dbcfg.MaxConn), db.MaxQueryTime(dbcfg.MaxQueryTime.Duration), ) if err != nil { return err } log.Debug("InitDb Success", zap.String("drive", dbcfg.Drivename), zap.String("DSN", dbcfg.Dsn)) return nil } // InitLog @Description // @Author J 2022/7/26 15:30 func InitLog() { logcfg := config.Conf.Log err := log.InitLog( log.Path(logcfg.LogPath), log.Level(logcfg.LogLevel), log.Compress(logcfg.Compress), log.MaxSize(logcfg.MaxSize), log.MaxBackups(logcfg.MaxBackups), log.MaxAge(logcfg.MaxAge), log.Format(logcfg.Format), ) if err != nil { fmt.Printf("InitLog failed: %v\n", err) os.Exit(1) } }