2023-09-21 17:33:59 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-11-30 11:37:02 +08:00
|
|
|
"github.com/gin-gonic/gin"
|
2023-10-11 09:21:07 +08:00
|
|
|
"go-wechat/config"
|
2023-10-26 10:07:08 +08:00
|
|
|
"go-wechat/initialization"
|
2023-11-30 11:37:02 +08:00
|
|
|
"go-wechat/router"
|
2023-09-21 17:33:59 +08:00
|
|
|
"go-wechat/tasks"
|
2023-11-30 11:37:02 +08:00
|
|
|
"go-wechat/tcpserver"
|
2023-10-26 10:07:08 +08:00
|
|
|
"go-wechat/utils"
|
2023-09-21 17:33:59 +08:00
|
|
|
"log"
|
2023-10-26 10:07:08 +08:00
|
|
|
"time"
|
2023-09-21 17:33:59 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2023-10-26 10:07:08 +08:00
|
|
|
initialization.InitConfig()
|
2023-09-21 17:33:59 +08:00
|
|
|
tasks.InitTasks()
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2023-10-26 10:07:08 +08:00
|
|
|
// 如果启用了自动配置回调,就设置一下
|
|
|
|
if config.Conf.Wechat.AutoSetCallback {
|
|
|
|
utils.ClearCallback()
|
|
|
|
time.Sleep(500 * time.Millisecond) // 休眠五百毫秒再设置
|
|
|
|
utils.SetCallback(config.Conf.Wechat.Callback)
|
|
|
|
}
|
|
|
|
|
2023-11-30 11:37:02 +08:00
|
|
|
// 启动TCP服务
|
|
|
|
go tcpserver.Start()
|
2023-09-21 17:33:59 +08:00
|
|
|
|
2023-11-30 11:37:02 +08:00
|
|
|
// 启动HTTP服务
|
|
|
|
app := gin.Default()
|
|
|
|
app.LoadHTMLGlob("views/*.html")
|
2023-11-30 14:20:48 +08:00
|
|
|
app.Static("/assets", "./views/static")
|
2023-11-30 11:37:02 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|