cmd

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Main = gcmd.Command{
		Name:  "KysionShared",
		Usage: "KysionShared",
		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")
					})
				}
			}

			{

				consts.Global.DefaultRegisterType = g.Cfg().MustGet(ctx, "service.userDefaultType", 0).Int()

				consts.Global.NotAllowLoginUserTypeArr = garray.NewSortedIntArrayFrom(g.Cfg().MustGet(ctx, "service.allowLoginUserType", "[-1]").Ints())

				consts.Global.NotAllowLoginUserTypeArr.Unique()
			}

			{
				serviceWorkerId := g.Cfg().MustGet(ctx, "service.idGeneratorWorkerId").Uint16()
				if serviceWorkerId < 1 || serviceWorkerId > 63 {
					g.Log().Fatal(ctx, "service.serviceWorkerId 取值范围只能是 1 ~ 63")
					return nil
				}

				// 创建 IdGeneratorOptions 对象,请在构造函数中输入 WorkerId:
				var options = idgen.NewIdGeneratorOptions(serviceWorkerId)
				options.WorkerIdBitLength = 10

				idgen.SetIdGenerator(options)
			}

			{

				validator.RegisterServicePhone()
			}

			{

				sys_service.Casbin().Enforcer()
			}

			{

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

					group.Middleware(
						sys_service.Middleware().Casbin,
						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) })
					})
				})
			}

			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