Files

59 lines
1.5 KiB
Go

package cmd
import (
"context"
"git.5iot.com/iotlcm-public/iotlcm-app/internal/cmd/inithttp"
"git.5iot.com/iotlcm-public/iotlcm-app/internal/library/websocket"
"git.5iot.com/iotlcm-public/iotlcm-app/internal/router"
"git.5iot.com/iotlcm-public/iotlcm-app/internal/service"
"git.5iot.com/iotlcm-public/iotlcm-app/internal/service/allocatedispatch"
"git.5iot.com/iotlcm-public/iotlcm-app/internal/tasks"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gcmd"
_ "git.5iot.com/iotlcm-public/iotlcm-app/internal/queues/httpqueues"
)
func init() {
inithttp.RegisterHttpInitFunc("initJobTask", initJobTask)
}
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
}
dumpRouterMap := g.Cfg().MustGet(ctx, "server.dumpRouterMap", false).Bool()
s.SetDumpRouterMap(dumpRouterMap)
router.InitRouter(ctx, s)
websocket.StartWebSocket(ctx)
stopAllocateRecovery := allocatedispatch.Start(ctx)
defer stopAllocateRecovery()
s.Run()
stopAllocateRecovery()
inithttp.CleanupHttp(ctx)
return nil
},
}
func initJobTask(ctx context.Context) error {
tasks.TasksInstance(ctx)
service.SysJob().InitRegister()
return nil
}