package main

import (
	"context"

	"ipsomc/core/dao/mysql/mysqlapi"
	"ipsomc/core/dao/redis/redisapi"
	"ipsomc/core/router"
	"ipsomc/module/socket/socketcreate"
	"ipsomc/module/timer"
	"ipsomc/util"

	"github.com/gin-gonic/gin"
	_ "github.com/jinzhu/gorm/dialects/mysql"
)

var socketCreateApi socketcreate.SocketCreate

func main() {
	ctx := context.Background()

	//初始化配置文件
	util.ViperConfigInit("config", "config")

	//创建定时器
	go timer.CreateTimer()

	//创建socket监听
	//go socketCreateApi.CreateUdpSocket()
	go socketCreateApi.CreateTcpSocket()

	//打开redis数据库
	redisapi.OpenRds(ctx, "redisDefault")
	defer redisapi.CloseRds()

	//打开MySql数据库
	mysqlapi.OpenSqlDb()
	defer mysqlapi.CloseSqlDb()

	//注册并启动路由
	r := router.SetRouter(gin.DebugMode)
	//r := router.SetRouter(gin.ReleaseMode)
	r.Run(":8080") //监听
}
