cmd

package
v1.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Main = gcmd.Command{
		Name:  "main",
		Usage: "main",
		Brief: "start sagoo-iot server",
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
			var (
				s = g.Server()
			)

			uploadPath := g.Cfg().MustGet(ctx, "upload.path").String()
			if uploadPath == "" {
				g.Log().Fatal(ctx, "文件上传配置路径不能为空")
			}

			if gmode.IsDevelop() {
				s.BindHookHandler("/*", ghttp.HookBeforeServe, func(r *ghttp.Request) {
					r.Response.Header().Set("Cache-Control", "no-store")
				})
			}

			s.BindHookHandler("/*", ghttp.HookAfterOutput, func(r *ghttp.Request) {
				service.Middleware().OperationLog(r)
			})

			s.Group("/subscribe", func(group *ghttp.RouterGroup) {
				group.GET("/sysenv", notifier.SysenvMessageEvent)
			})

			s.Group("/api/v1", func(group *ghttp.RouterGroup) {

				group.Middleware(
					service.Middleware().Ctx,
					service.Middleware().ResponseHandler,
					service.Middleware().MiddlewareCORS,
				)

				router.System(ctx, group)
				router.Business(ctx, group)

			})

			if err := service.SysAuthorize().InitAuthorize(ctx); err != nil {
				g.Log().Fatal(ctx, "系统权限缓存初始化失败:", err)
			}

			if err := service.SystemPluginsConfig().UpdateAllPluginsConfigCache(); err != nil {
				g.Log().Error(ctx, "初始化插件配置数据失败:", err)
			}

			if err := service.TSLTable().CreateDatabase(ctx); err != nil {
				g.Log().Fatal(ctx, "TDengine 数据库创建失败:", err)
			}
			if err := service.TdLogTable().CreateStable(ctx); err != nil {
				g.Log().Fatal(ctx, "TDengine 日志超级表创建失败:", err)
			}
			if err := mqtt.InitSystemMqtt(); err != nil {
				g.Log().Errorf(ctx, "MQTT 初始化mqtt客户端失败,失败原因:%+#v", err)
			}
			defer mqtt.Close()

			if err := network.ReloadNetwork(context.Background()); err != nil {
				g.Log().Errorf(ctx, "载入网络错误,错误原因:%+#v", err)
			}

			task.StartInit()

			enhanceOpenAPIDoc(s)

			s.Run()
			return
		},
	}
)

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL