Files
iotlcm/server/internal/cmd/http.go
T
2026-10-29 14:36:49 +08:00

67 lines
1.8 KiB
Go

package cmd
import (
"context"
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/cmd/inithttp"
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/library/exportcenter"
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/library/rabbitmq"
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/library/websocket"
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/router"
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/service"
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/tasks"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gcmd"
_ "git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/queues/httpqueues"
)
func init() {
inithttp.RegisterHttpInitFunc("initJobTask", initJobTask)
inithttp.RegisterHttpInitFunc("exportCenter", initExportCenter)
inithttp.RegisterHttpCleanupFunc("rabbitmq", func(ctx context.Context) error {
return rabbitmq.Close()
})
}
// initExportCenter 导出中心:补偿上次进程遗留的任务,并启动过期文件清理。
func initExportCenter(ctx context.Context) error {
exportcenter.RecoverOnStart(ctx)
exportcenter.StartCleanup(ctx)
return nil
}
var Http = &gcmd.Command{
Name: "http",
Usage: "http",
Brief: "HTTP控制台服务",
Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
g.Log().Infof(ctx, "Http init start")
serverWg.Add(1)
s := g.Server()
go func() {
waitServerClose(ctx)
websocket.StopWebSocket(ctx)
s.Shutdown()
serverWg.Done()
}()
err = inithttp.InitHttp(ctx)
if err != nil {
g.Log().Errorf(ctx, "http init error: %v", err)
return err
}
s.SetDumpRouterMap(true)
router.InitRouter(ctx, s)
websocket.StartWebSocket(ctx)
s.Run()
inithttp.CleanupHttp(ctx)
return nil
},
}
func initJobTask(ctx context.Context) error {
tasks.TasksInstance(ctx)
service.SysJob().InitRegister()
return nil
}