package main import ( "github.com/gin-gonic/gin" _ "github.com/go-sql-driver/mysql" "github.com/jinzhu/gorm" device "iot_manager_service/app/device/dao" multimedia "iot_manager_service/app/multimedia/dao" system "iot_manager_service/app/system/dao" "iot_manager_service/config" _ "iot_manager_service/config" "iot_manager_service/router" "iot_manager_service/util/cache" "iot_manager_service/util/logger" "net/url" ) func main() { // 开始调试模式 gin.SetMode("debug") logger.InitLog() // 实例化配置 initDB() err := cache.InitRedis() if err != nil { panic(err) } engine := gin.Default() router.InitRouter(engine) _ = engine.Run(config.Instance().Server.Address) } func initDB() { cfg := config.Instance() dsn := cfg.Database.User + ":" + cfg.Database.Password + "@tcp(" + cfg.Database.Host + ":" + cfg.Database.Port + ")/" + cfg.Database.Name + "?charset=utf8&parseTime=True" + "&loc=" + url.QueryEscape(cfg.Database.Timezone) db, err := gorm.Open("mysql", dsn) if err != nil { panic(err) } else { db.DB().SetMaxOpenConns(32) db.DB().SetMaxIdleConns(5) db.LogMode(false) db.SetLogger(logger.Logger) } device.InitDB(db) system.InitDB(db) multimedia.InitDB(db) }