boot

package
v0.8.27 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: MIT 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 http server",
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
			var (
				s   = g.Server()
				oai = s.GetOpenApi()
			)

			{

				oai.Info.Title = `API Reference`
				oai.Config.CommonResponse = api_v1.JsonRes{}
				oai.Config.CommonResponseDataField = `Data`
			}

			{

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

				s.AddStaticPath("/upload", uploadPath)
			}

			{

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

			{

				sys_service.SysPermission().ImportPermissionTree(ctx, consts.Global.PermissionTree, nil)

				sys_service.SysPermission().ImportPermissionTree(ctx, consts.Global.FinancialPermissionTree, nil)

				sys_service.Casbin().Enforcer()
			}

			apiPrefix := g.Cfg().MustGet(ctx, "service.apiPrefix").String()
			s.Group(apiPrefix, func(group *ghttp.RouterGroup) {

				group.Middleware(

					sys_service.Middleware().CTX,
					sys_service.Middleware().ResponseHandler,
				)

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

					group.Group("/auth", func(group *ghttp.RouterGroup) { group.Bind(sys_controller.Auth) })

					group.Group("/common", func(group *ghttp.RouterGroup) {
						group.Bind(

							sys_controller.Captcha,

							sys_controller.SysArea,
						)
					})
				})

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

					group.Middleware(
						sys_service.Middleware().Auth,
					)

					router.ModulesGroup(consts.Global.IModules, group)

					router.FinancialGroup(consts.Global.IModules, group)

					group.Group("/audit", func(group *ghttp.RouterGroup) { group.Bind(sys_controller.SysAudit) })

					group.Group("/person_license", func(group *ghttp.RouterGroup) { group.Bind(sys_controller.SysLicense) })

					group.Group("/license", func(group *ghttp.RouterGroup) { group.Bind(lincense.License) })

				})
			})
			s.Run()
			return nil
		},
	}
)

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