Documentation ¶
Index ¶
- func Category() string
- func Clean() error
- func GenTemplates() error
- func GetGroup(service parser.Service) (data []string)
- func GetGroupName(rpc *parser.RPC) string
- func ProtoTmpl(out string) error
- func RevertTemplate(name string) error
- func Update() error
- type Dir
- type DirContext
- type Generator
- func (g *Generator) GenBaseDesc(ctx DirContext, _ parser.Proto, cfg *conf.Config, c *ZRpcContext) error
- func (g *Generator) GenCall(ctx DirContext, proto parser.Proto, cfg *conf.Config, c *ZRpcContext) error
- func (g *Generator) GenConfig(ctx DirContext, _ parser.Proto, cfg *conf.Config, c *ZRpcContext) error
- func (g *Generator) GenEntInitCode(zctx *ZRpcContext, abs string) error
- func (g *Generator) GenEntTx(ctx DirContext, _ parser.Proto, cfg *conf.Config, c *ZRpcContext) error
- func (g *Generator) GenErrorHandler(ctx DirContext, _ parser.Proto, cfg *conf.Config, c *ZRpcContext) error
- func (g *Generator) GenEtc(ctx DirContext, _ parser.Proto, cfg *conf.Config, c *ZRpcContext) error
- func (g *Generator) GenLogic(ctx DirContext, proto parser.Proto, cfg *conf.Config, c *ZRpcContext) error
- func (g *Generator) GenMain(ctx DirContext, proto parser.Proto, cfg *conf.Config, c *ZRpcContext) error
- func (g *Generator) GenPb(ctx DirContext, c *ZRpcContext) error
- func (g *Generator) GenServer(ctx DirContext, proto parser.Proto, cfg *conf.Config, c *ZRpcContext) error
- func (g *Generator) GenSvc(ctx DirContext, _ parser.Proto, cfg *conf.Config, c *ZRpcContext) error
- func (g *Generator) Generate(zctx *ZRpcContext) error
- func (g *Generator) Prepare() error
- type MainServiceTemplateData
- type ZRpcContext
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Category ¶
func Category() string
Category returns a const string value for rpc template category
func GenTemplates ¶
func GenTemplates() error
GenTemplates is the entry for command goctl template, it will create the specified category
func GetGroupName ¶
func RevertTemplate ¶
RevertTemplate restores the deleted template files
Types ¶
type Dir ¶
type Dir struct { Base string Filename string Package string GetChildPackage func(childPath string) (string, error) }
Dir defines a directory
type DirContext ¶
type DirContext interface { GetCall() Dir GetEtc() Dir GetInternal() Dir GetConfig() Dir GetLogic() Dir GetServer() Dir GetSvc() Dir GetPb() Dir GetProtoGo() Dir GetMain() Dir GetServiceName() stringx.String SetPbDir(pbDir, grpcDir string) }
DirContext defines a rpc service directories context
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator defines the environment needs of rpc service generation
func NewGenerator ¶
NewGenerator returns an instance of Generator
func (*Generator) GenBaseDesc ¶
func (g *Generator) GenBaseDesc(ctx DirContext, _ parser.Proto, cfg *conf.Config, c *ZRpcContext) error
func (*Generator) GenCall ¶
func (g *Generator) GenCall(ctx DirContext, proto parser.Proto, cfg *conf.Config, c *ZRpcContext) error
GenCall generates the rpc client code, which is the entry point for the rpc service call. It is a layer of encapsulation for the rpc client and shields the details in the pb.
func (*Generator) GenConfig ¶
func (g *Generator) GenConfig(ctx DirContext, _ parser.Proto, cfg *conf.Config, c *ZRpcContext) error
GenConfig generates the configuration structure definition file of the rpc service, which contains the zrpc.RpcServerConf configuration item by default. You can specify the naming style of the target file name through config.Config. For details, see https://github.com/zeromicro/go-zero/tree/master/tools/goctl/config/config.go
func (*Generator) GenEntInitCode ¶ added in v1.6.13
func (g *Generator) GenEntInitCode(zctx *ZRpcContext, abs string) error
func (*Generator) GenEntTx ¶
func (g *Generator) GenEntTx(ctx DirContext, _ parser.Proto, cfg *conf.Config, c *ZRpcContext) error
func (*Generator) GenErrorHandler ¶
func (g *Generator) GenErrorHandler(ctx DirContext, _ parser.Proto, cfg *conf.Config, c *ZRpcContext) error
func (*Generator) GenEtc ¶
func (g *Generator) GenEtc(ctx DirContext, _ parser.Proto, cfg *conf.Config, c *ZRpcContext) error
GenEtc generates the yaml configuration file of the rpc service, including host, port monitoring configuration items and etcd configuration
func (*Generator) GenLogic ¶
func (g *Generator) GenLogic(ctx DirContext, proto parser.Proto, cfg *conf.Config, c *ZRpcContext, ) error
GenLogic generates the logic file of the rpc service, which corresponds to the RPC definition items in proto.
func (*Generator) GenMain ¶
func (g *Generator) GenMain(ctx DirContext, proto parser.Proto, cfg *conf.Config, c *ZRpcContext) error
GenMain generates the main file of the rpc service, which is a rpc service program call entry
func (*Generator) GenPb ¶
func (g *Generator) GenPb(ctx DirContext, c *ZRpcContext) error
GenPb generates the pb.go file, which is a layer of packaging for protoc to generate gprc, but the commands and flags in protoc are not completely joined in goctl. At present, proto_path(-I) is introduced
func (*Generator) GenServer ¶
func (g *Generator) GenServer(ctx DirContext, proto parser.Proto, cfg *conf.Config, c *ZRpcContext, ) error
GenServer generates rpc server file, which is an implementation of rpc server
func (*Generator) GenSvc ¶
func (g *Generator) GenSvc(ctx DirContext, _ parser.Proto, cfg *conf.Config, c *ZRpcContext) error
GenSvc generates the servicecontext.go file, which is the resource dependency of a service, such as rpc dependency, model dependency, etc.
func (*Generator) Generate ¶
func (g *Generator) Generate(zctx *ZRpcContext) error
Generate generates a rpc service, through the proto file, code storage directory, and proto import parameters to control the source file and target location of the rpc service that needs to be generated
type MainServiceTemplateData ¶
type ZRpcContext ¶
type ZRpcContext struct { // Sre is the source file of the proto. Src string // ProtoCmd is the command to generate proto files. ProtocCmd string // ProtoGenGrpcDir is the directory to store the generated proto files. ProtoGenGrpcDir string // ProtoGenGoDir is the directory to store the generated go files. ProtoGenGoDir string // IsGooglePlugin is the flag to indicate whether the proto file is generated by google plugin. IsGooglePlugin bool // GoOutput is the output directory of the generated go files. GoOutput string // GrpcOutput is the output directory of the generated grpc files. GrpcOutput string // Output is the output directory of the generated files. Output string // Multiple is the flag to indicate whether the proto file is generated in multiple mode. Multiple bool // Schema is the ent schema path Schema string // Ent Ent bool // ModuleName is the module name in go mod ModuleName string // Port describes the service port exposed Port int // MakeFile describes whether generate makefile MakeFile bool // DockerFile describes whether generate dockerfile DockerFile bool // DescDir describes whether to create desc folder for splitting proto files UseDescDir bool // RpcName describes the rpc name when create new project RpcName string // I18n describes whether to use i18n I18n bool // Whether to generate rpc client IsGenClient bool // IsNewProject describe whether is new project IsNewProject bool }