Documentation ¶
Index ¶
- Constants
- Variables
- func BindHttpHealthApi(group *ghttp.RouterGroup)
- func GenHttpForGrpcCmd(controllers []*GrpcController, folderPath string) (err error)
- func GenMain(mainSrv gcmd.Command, subSrv ...*gcmd.Command) gcmd.Command
- func GetCommonArguments(ctx context.Context, parser *gcmd.Parser, pattern string, isGrpc ...bool) (ret *gvar.Var)
- func GetConsumeCmdFunc(name string, middleware MiddlewareForCmd, consumeFunc ConsumeFunc) func(ctx context.Context, parser *gcmd.Parser) error
- func GetGrpcCmdFunc(middleware MiddlewareForCmd, grpcRegFunc GrpcRegFunc) func(ctx context.Context, parser *gcmd.Parser) error
- func GetHttpCmdFunc(middleware MiddlewareForCmd, useMiddlewares []ghttp.HandlerFunc, ...) func(ctx context.Context, parser *gcmd.Parser) error
- func GetXxljobCmdFunc(middleware MiddlewareForCmd, taskMap map[string]xxl.TaskFunc) func(ctx context.Context, parser *gcmd.Parser) error
- func GoFmt(path string)
- func HttpForGrpcFunc(r *ghttp.Request, req interface{}, ...)
- type ConsumeFunc
- type GrpcController
- type GrpcMethod
- type GrpcRegFunc
- type HttpCmdOption
- type HttpCmdOptionApply
- func WithHttpCmdAccessLogMiddleware(v func(r *ghttp.Request)) HttpCmdOptionApply
- func WithHttpCmdBindHttpHealthApi(v func(group *ghttp.RouterGroup)) HttpCmdOptionApply
- func WithHttpCmdErrorLogMiddleware(v func(r *ghttp.Request)) HttpCmdOptionApply
- func WithHttpCmdLogFormatJsonMiddleware(v func(r *ghttp.Request)) HttpCmdOptionApply
- func WithHttpCmdResponseMiddleware(v func(r *ghttp.Request)) HttpCmdOptionApply
- type MiddlewareForCmd
- type ServerGroup
Constants ¶
View Source
const ( ApolloIP = "apolloIp" Port = "port" )
Variables ¶
View Source
var CheckCfgCmd = &gcmd.Command{ Name: "checkCfg", Usage: "./main checkCfg", Brief: "check config", Description: "检查配置文件是否符合规范", Arguments: append(CommonArguments, []gcmd.Argument{ { Name: "env", Short: "e", Brief: "要检查的环境,可选值: prod, dev。默认dev", IsArg: false, Orphan: false, }, { Name: "all", Short: "a", Brief: "强制检查下方所有配置", IsArg: false, Orphan: true, }, { Name: "grpc", Short: "g", Brief: "强制检查grpc服务配置", IsArg: false, Orphan: true, }, { Name: "server", Short: "s", Brief: "强制检查server服务配置", IsArg: false, Orphan: true, }, { Name: "rocketmq", Short: "m", Brief: "强制检查rocketmq配置", IsArg: false, Orphan: true, }, { Name: "xxljob", Short: "j", Brief: "强制检查xxlJob配置", IsArg: false, Orphan: true, }, { Name: "apollo", Short: "c", Brief: "强制检查apollo配置", IsArg: false, Orphan: true, }, { Name: "otlp", Short: "o", Brief: "强制检查otlp链路追踪配置", IsArg: false, Orphan: true, }, { Name: "registry", Short: "y", Brief: "强制检查服务注册发现registry配置", IsArg: false, Orphan: true, }, { Name: "redis", Short: "r", Brief: "强制检查服务注册发现redis配置", IsArg: false, Orphan: true, }, { Name: "database", Short: "d", Brief: "强制检查数据库配置", IsArg: false, Orphan: true, }, }..., ), Func: func(ctx context.Context, parser *gcmd.Parser) (err error) { cfg.Check(ctx, parser, GetCommonArguments(ctx, parser, Port).String()) return }, }
View Source
var ( // CommonArguments 命令行公共参数 CommonArguments = []gcmd.Argument{ { Name: Port, Short: "", Brief: "端口,参考格式:`:8080`,默认使用配置文件的`server.address`", IsArg: false, Orphan: false, }, { Name: ApolloIP, Short: "", Brief: "apollo连接地址,默认使用配置文件的`apollo.IP`或无", IsArg: false, Orphan: false, }, } )
View Source
var ( GenHttpForGrpc = &gcmd.Command{ Name: "genHttpForGrpc", Usage: "./main genHttpForGrpc", Brief: "gen http for grpc cmd and controller", Arguments: append(CommonArguments, []gcmd.Argument{ { Name: "sources", Short: "s", Brief: "grpc的控制器文件路径,多个文件逗号分割,可以是基于根目录的相对路径,或绝对路径", IsArg: false, Orphan: false, }, { Name: "output", Short: "o", Brief: "控制器文件输出目录,默认为`internal/controller/http/`", IsArg: false, Orphan: false, }, { Name: "cmd", Short: "c", Brief: "cmd文件输出目录,默认为`internal/cmd/`", IsArg: false, Orphan: false, }, }...), Func: func(ctx context.Context, parser *gcmd.Parser) (err error) { controllerPath := parser.GetOpt("sources", "").String() folderPath := parser.GetOpt("output", "internal/controller/http/").String() cmdFolderPath := parser.GetOpt("cmd", "internal/cmd/").String() if strings.TrimSpace(controllerPath) == "" { return fmt.Errorf("output is empty") } var controllers []*GrpcController for _, v := range strings.Split(controllerPath, ",") { ret, err1 := GenHttpForGrpcControllers(v, folderPath) if err1 != nil { err = err1 return } controllers = append(controllers, ret...) } err = GenHttpForGrpcCmd(controllers, cmdFolderPath) if err != nil { return } return }, } )
Functions ¶
func BindHttpHealthApi ¶
func BindHttpHealthApi(group *ghttp.RouterGroup)
BindHttpHealthApi 绑定健康检查api
func GenHttpForGrpcCmd ¶
func GenHttpForGrpcCmd(controllers []*GrpcController, folderPath string) (err error)
func GetCommonArguments ¶
func GetConsumeCmdFunc ¶
func GetConsumeCmdFunc(name string, middleware MiddlewareForCmd, consumeFunc ConsumeFunc) func(ctx context.Context, parser *gcmd.Parser) error
GetConsumeCmdFunc 标准化消费者服务方法
示例: gcmd.Command{ Name: "demoConsumer", Usage: "./main demoConsumer", Brief: "批量删除博客的消费者", Func: cmd.GetConsumeCmdFunc("demoConsumer", cmd.GetGrpcMiddleware(), demoConsumeFunc), }
func GetGrpcCmdFunc ¶
func GetGrpcCmdFunc(middleware MiddlewareForCmd, grpcRegFunc GrpcRegFunc) func(ctx context.Context, parser *gcmd.Parser) error
GetGrpcCmdFunc 标准化grpc服务方法
示例: gcmd.Command{ Name: "main", Usage: "./main", Brief: "主命令", Func: cmd.GetGrpcCmdFunc(cmd.GetGrpcMiddleware(), func(server *grpcx.GrpcServer){ demoController.Register(server) }), }
func GetHttpCmdFunc ¶
func GetHttpCmdFunc(middleware MiddlewareForCmd, useMiddlewares []ghttp.HandlerFunc, serverGroups []ServerGroup, optionApplyFuncs ...HttpCmdOptionApply) func(ctx context.Context, parser *gcmd.Parser) error
GetHttpCmdFunc 标准化http服务方法
示例: gcmd.Command{ Name: "main", Usage: "main", Brief: "start http server", Func: cmd.GetHttpCmdFunc( cmd.GetHttpMiddleware(), []ghttp.HandlerFunc{}, []cmd.ServerGroup{ { Prefix: "/", Middlewares: []ghttp.HandlerFunc{}, Controllers: []interface{}{ controller.Demo, }, }, }, ), }
func GetXxljobCmdFunc ¶
func GetXxljobCmdFunc(middleware MiddlewareForCmd, taskMap map[string]xxl.TaskFunc) func(ctx context.Context, parser *gcmd.Parser) error
GetXxljobCmdFunc 标准化xxljob服务方法
示例: gcmd.Command{ Name: "xxlJob", Usage: "./main xxlJob", Brief: "定时任务", Func: cmd.GetConsumeCmdFunc(cmd.GetGrpcMiddleware(), map[string]xxl.TaskFunc{ "task1": func(cxt context.Context, param *RunReq) string{return ""}, "task2": func(cxt context.Context, param *RunReq) string{return ""} }]), }
Types ¶
type ConsumeFunc ¶
type GrpcController ¶
type GrpcController struct { ControllerName string //原始控制器完整包及名称 Package string //包名 Name string //控制器名称 OriginName string //原始结构体名称 Methods []*GrpcMethod //方法列表 }
func GenHttpForGrpcControllers ¶
func GenHttpForGrpcControllers(controllerPath string, folderPath string) (controllers []*GrpcController, err error)
func ParseGrpcControllerFile ¶
func ParseGrpcControllerFile(filePath string) (controllers []*GrpcController, err error)
type GrpcMethod ¶
type HttpCmdOption ¶
type HttpCmdOptionApply ¶
type HttpCmdOptionApply func(option *HttpCmdOption)
func WithHttpCmdAccessLogMiddleware ¶
func WithHttpCmdAccessLogMiddleware(v func(r *ghttp.Request)) HttpCmdOptionApply
func WithHttpCmdBindHttpHealthApi ¶
func WithHttpCmdBindHttpHealthApi(v func(group *ghttp.RouterGroup)) HttpCmdOptionApply
func WithHttpCmdErrorLogMiddleware ¶
func WithHttpCmdErrorLogMiddleware(v func(r *ghttp.Request)) HttpCmdOptionApply
func WithHttpCmdLogFormatJsonMiddleware ¶
func WithHttpCmdLogFormatJsonMiddleware(v func(r *ghttp.Request)) HttpCmdOptionApply
func WithHttpCmdResponseMiddleware ¶
func WithHttpCmdResponseMiddleware(v func(r *ghttp.Request)) HttpCmdOptionApply
type MiddlewareForCmd ¶
type ServerGroup ¶
type ServerGroup struct { Prefix string //前缀,默认"/" Middlewares []ghttp.HandlerFunc Controllers []interface{} }
Click to show internal directories.
Click to hide internal directories.