cmd

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: MIT Imports: 12 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) {

			s := g.Server()

			s.BindHookHandler("/*", ghttp.HookBeforeServe, beforeServeHook)

			s.Group("/", func(g *ghttp.RouterGroup) {
				g.Middleware(MiddlewareAuth)
				g.Middleware(MiddlewareHandlerResponse)
				g.Bind()
			})

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

				v1.Middleware(MiddlewareAuth)
				v1.Middleware(MiddlewareHandlerResponse)

				v1.Group("/chat", func(g *ghttp.RouterGroup) {
					g.Bind(
						chat.NewV1(),
					)
				})

				v1.Group("/token", func(g *ghttp.RouterGroup) {
					g.Bind(
						token.NewV1(),
					)
				})
			})

			s.Run()
			return nil
		},
	}
)

Functions

func MiddlewareAuth

func MiddlewareAuth(r *ghttp.Request)

func MiddlewareHandlerResponse

func MiddlewareHandlerResponse(r *ghttp.Request)

MiddlewareHandlerResponse is the default middleware handling handler response object and its error.

Types

type DefaultHandlerResponse

type DefaultHandlerResponse struct {
	Code    int         `json:"code"    dc:"Error code"`
	Message string      `json:"message" dc:"Error message"`
	Data    interface{} `json:"data"    dc:"Result data for certain request according API definition"`
}

DefaultHandlerResponse is the default implementation of HandlerResponse.

Jump to

Keyboard shortcuts

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