1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- package main
- import (
- "github.com/gin-gonic/gin"
- "github.com/jinzhu/gorm"
- device "iot_manager_service/app/device/dao"
- system "iot_manager_service/app/system/dao"
- "iot_manager_service/config"
- _ "iot_manager_service/config"
- "iot_manager_service/router"
- "iot_manager_service/util"
- "net/url"
- )
- func main() {
- // 开始调试模式
- gin.SetMode("debug")
- // 实例化配置
- initDB()
- err := util.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)
- }
- device.InitDB(db)
- system.InitDB(db)
- }
|