123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- package main
- import (
- "fmt"
- "github.com/gin-gonic/gin"
- "github.com/gographics/gmagick"
- "os"
- setting "icloudapp.cn/tools/config"
- log "icloudapp.cn/tools/logger"
- "icloudapp.cn/tools/repository/mysql"
- "icloudapp.cn/tools/repository/redis"
- "icloudapp.cn/tools/router"
- "icloudapp.cn/tools/util/jobs"
- )
- func main() {
- /*if len(os.Args) < 2 {
- fmt.Println("need config file.eg: config.yaml")
- return
- }
- // 1.加载配置
- setting.Init(os.Args[1])
- */
- gmagick.Initialize()
- defer gmagick.Terminate()
- gin.SetMode(gin.DebugMode)
- setting.Init(gin.EnvGinMode)
- // 2.初始化日志
- log.Init()
- // 3.初始化mysql
- mysql.Init(setting.Conf.MySQLConfig)
- // 4.如果参数为 migrate就初始化表结构
- if len(os.Args) >= 3 && os.Args[2] == "migrate" {
- mysql.AutoMigrateDB()
- fmt.Println("run AutoMigrate success!")
- return
- }
- // 5.初始化redis
- redis.Init(setting.Conf.RedisConfig)
- // 6.初始化定时任务
- jobs.InitJobs()
- // 7.注册路由
- r := router.InitRouter()
- r.Run(fmt.Sprintf(":%d", setting.Conf.Port))
- }
|