cmd

package
v0.2.79 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Main = gcmd.Command{
		Name:  "Kysion Gf Admin Community",
		Usage: "Kysion Gf Admin Community",
		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.Casbin().Enforcer()

				sys_service.SysPermission().ImportPermissionTree(ctx, sys_consts.PermissionTree, nil)
			}

			{

				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("/sys_auth", func(group *ghttp.RouterGroup) { group.Bind(sysController.Auth) })

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

								sysController.Captcha,

								sysController.SysSms,

								sysController.SysArea,
							)
						})
					})

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

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

						group.Group("/common/sys_file", func(group *ghttp.RouterGroup) { group.Bind(sysController.SysFile) })

						group.Group("/system/config", func(group *ghttp.RouterGroup) { group.Bind(sysController.SysConfig) })

						group.Group("/user", func(group *ghttp.RouterGroup) { group.Bind(sysController.SysUser) })

						group.Group("/role", func(group *ghttp.RouterGroup) { group.Bind(sysController.SysRole) })

						group.Group("/permission", func(group *ghttp.RouterGroup) { group.Bind(sysController.SysPermission) })

						group.Group("/organization", func(group *ghttp.RouterGroup) { group.Bind(sysController.SysOrganization) })

						group.Group("/my", func(group *ghttp.RouterGroup) { group.Bind(sysController.SysMy) })
					})
				})
			}

			s.Run()
			return nil
		},
	}
)

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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