cmd

package
v0.0.0-...-bf4de7e Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Main = gcmd.Command{
		Name:        "reviewer",
		Usage:       "reviewer [OPTIONS]",
		Brief:       "@hitokoto-osc/reviewer 服务端",
		Description: "reviewer 服务端,用于提供 API 服务。",
		Examples: `
			Dev:
				./reviewer

			Test:
				./reviewer -c config.test.yaml
				or
				GF_GCFG_FILE=config.test.yaml GF_GERROR_BRIEF=true ./reviewer

			Prod:
				./reviewer -c config.prod.yaml
				or
				GF_GCFG_FILE=config.prod.yaml GF_GERROR_BRIEF=true ./reviewer`,
		Additional: "更多信息请访问 https://github.com/hitokoto-osc/reviewer",
		Arguments: []gcmd.Argument{
			{
				Name:   "version",
				Short:  "v",
				Brief:  "print version info",
				IsArg:  false,
				Orphan: true,
			},
			{
				Name:   "config",
				Short:  "c",
				Brief:  "config file (default config.yaml)",
				IsArg:  false,
				Orphan: false,
			},
		},
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
			if parser.GetOpt("version") != nil {
				utility.PrintVersionInfo()
				return nil
			}
			config := parser.GetOpt("config").String()
			if config != "" {
				g.Cfg().GetAdapter().(*gcfg.AdapterFile).SetFileName(config)
			}

			err = service.Job().Register(ctx)
			if err != nil {
				return gerror.Wrap(err, "注册计划任务失败")
			}

			s := g.Server()
			s.SetServerAgent(consts.AppName + " " + consts.Version)
			s.SetRouteOverWrite(true)
			s.AddSearchPath("resource/public")
			s.Use(service.Middleware().CORS)
			s.Use(service.Middleware().HandlerResponse)
			s.BindHandler("/", index.NewCommon().Index)
			s.Group("/api/v1", func(group *ghttp.RouterGroup) {
				group.Bind(index.NewV1())
				group.Group("/", func(group *ghttp.RouterGroup) {
					group.Middleware(
						service.Middleware().Ctx,
						service.Middleware().AuthorizationV1,
					)
					group.Bind(user.NewV1(), hitokoto.NewV1())
					group.Group("/", func(group *ghttp.RouterGroup) {
						group.Middleware(service.Middleware().GuardV1(consts.UserRoleReviewer))
						group.Bind(poll.NewV1())
					})
					group.GET("/poll/mark", poll.NewV1().GetPollMarks)
					group.Group("/admin", func(group *ghttp.RouterGroup) {
						group.Middleware(service.Middleware().GuardV1(consts.UserRoleAdmin))
						group.Bind(hitokoto.NewAdminV1())
						group.Bind(poll.NewAdminV1())
					})
				})
			})
			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