1
0
forked from lxh/go-wxhelper
go-wxhelper/main.go

47 lines
991 B
Go
Raw Permalink Normal View History

2023-09-21 17:33:59 +08:00
package main
import (
"github.com/gin-gonic/gin"
2023-10-11 09:21:07 +08:00
"go-wechat/config"
"go-wechat/initialization"
"go-wechat/router"
2023-09-21 17:33:59 +08:00
"go-wechat/tasks"
"go-wechat/tcpserver"
"go-wechat/utils"
2023-09-21 17:33:59 +08:00
"log"
"time"
2023-09-21 17:33:59 +08:00
)
func init() {
initialization.InitConfig()
2023-09-21 17:33:59 +08:00
tasks.InitTasks()
}
func main() {
// 如果启用了自动配置回调,就设置一下
if config.Conf.Wechat.AutoSetCallback {
utils.ClearCallback()
time.Sleep(500 * time.Millisecond) // 休眠五百毫秒再设置
utils.SetCallback(config.Conf.Wechat.Callback)
}
// 启动TCP服务
go tcpserver.Start()
2023-09-21 17:33:59 +08:00
// 启动HTTP服务
app := gin.Default()
app.LoadHTMLGlob("views/*.html")
app.Static("/assets", "./views/assets")
app.StaticFile("/favicon.ico", "./views/wechat.ico")
// 404返回数据
app.NoRoute(func(ctx *gin.Context) {
// 404直接跳转到首页
ctx.Redirect(302, "/index.html")
})
// 初始化路由
router.Init(app)
if err := app.Run(":8080"); err != nil {
log.Panicf("服务启动失败:%v", err)
2023-09-21 17:33:59 +08:00
}
}