Documentation ¶
Index ¶
- func Category() string
- func Clean() error
- func GenTemplates(_ *cli.Context) error
- func ProtoTmpl(out string) error
- func RevertTemplate(name string) error
- func Update() error
- type DefaultGenerator
- func (g *DefaultGenerator) GenCall(ctx DirContext, proto parser.Proto, cfg *conf.Config) error
- func (g *DefaultGenerator) GenConfig(ctx DirContext, _ parser.Proto, cfg *conf.Config) error
- func (g *DefaultGenerator) GenEtc(ctx DirContext, _ parser.Proto, cfg *conf.Config) error
- func (g *DefaultGenerator) GenLogic(ctx DirContext, proto parser.Proto, cfg *conf.Config) error
- func (g *DefaultGenerator) GenMain(ctx DirContext, proto parser.Proto, cfg *conf.Config) error
- func (g *DefaultGenerator) GenPb(ctx DirContext, protoImportPath []string, proto parser.Proto, _ *conf.Config) error
- func (g *DefaultGenerator) GenServer(ctx DirContext, proto parser.Proto, cfg *conf.Config) error
- func (g *DefaultGenerator) GenSvc(ctx DirContext, _ parser.Proto, cfg *conf.Config) error
- func (g *DefaultGenerator) Prepare() error
- type Dir
- type DirContext
- type Generator
- type RPCGenerator
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 ¶
GenTemplates is the entry for command goctl template, it will create the specified category
func RevertTemplate ¶
RevertTemplate restores the deleted template files
Types ¶
type DefaultGenerator ¶
type DefaultGenerator struct {
// contains filtered or unexported fields
}
DefaultGenerator defines the environment needs of rpc service generation
func NewDefaultGenerator ¶
func NewDefaultGenerator() *DefaultGenerator
NewDefaultGenerator returns an instance of DefaultGenerator
func (*DefaultGenerator) GenCall ¶
func (g *DefaultGenerator) GenCall(ctx DirContext, proto parser.Proto, cfg *conf.Config) 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 (*DefaultGenerator) GenConfig ¶
func (g *DefaultGenerator) GenConfig(ctx DirContext, _ parser.Proto, cfg *conf.Config) 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/tal-tech/go-zero/tree/master/tools/goctl/config/config.go
func (*DefaultGenerator) GenEtc ¶
func (g *DefaultGenerator) GenEtc(ctx DirContext, _ parser.Proto, cfg *conf.Config) error
GenEtc generates the yaml configuration file of the rpc service, including host, port monitoring configuration items and etcd configuration
func (*DefaultGenerator) GenLogic ¶
func (g *DefaultGenerator) GenLogic(ctx DirContext, proto parser.Proto, cfg *conf.Config) error
GenLogic generates the logic file of the rpc service, which corresponds to the RPC definition items in proto.
func (*DefaultGenerator) GenMain ¶
func (g *DefaultGenerator) GenMain(ctx DirContext, proto parser.Proto, cfg *conf.Config) error
GenMain generates the main file of the rpc service, which is an rpc service program call entry
func (*DefaultGenerator) GenPb ¶
func (g *DefaultGenerator) GenPb(ctx DirContext, protoImportPath []string, proto parser.Proto, _ *conf.Config) 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 (*DefaultGenerator) GenServer ¶
func (g *DefaultGenerator) GenServer(ctx DirContext, proto parser.Proto, cfg *conf.Config) error
GenServer generates rpc server file, which is an implementation of rpc server
func (*DefaultGenerator) GenSvc ¶
func (g *DefaultGenerator) GenSvc(ctx DirContext, _ parser.Proto, cfg *conf.Config) error
GenSvc generates the servicecontext.go file, which is the resource dependency of a service, such as rpc dependency, model dependency, etc.
func (*DefaultGenerator) Prepare ¶
func (g *DefaultGenerator) Prepare() error
Prepare provides environment detection generated by rpc service, including go environment, protoc, whether protoc-gen-go is installed or not
type DirContext ¶
type DirContext interface { GetCall() Dir GetEtc() Dir GetInternal() Dir GetConfig() Dir GetLogic() Dir GetServer() Dir GetSvc() Dir GetPb() Dir GetMain() Dir GetServiceName() stringx.String }
DirContext defines a rpc service directories context
type Generator ¶
type Generator interface { Prepare() error GenMain(ctx DirContext, proto parser.Proto, cfg *conf.Config) error GenCall(ctx DirContext, proto parser.Proto, cfg *conf.Config) error GenEtc(ctx DirContext, proto parser.Proto, cfg *conf.Config) error GenConfig(ctx DirContext, proto parser.Proto, cfg *conf.Config) error GenLogic(ctx DirContext, proto parser.Proto, cfg *conf.Config) error GenServer(ctx DirContext, proto parser.Proto, cfg *conf.Config) error GenSvc(ctx DirContext, proto parser.Proto, cfg *conf.Config) error GenPb(ctx DirContext, protoImportPath []string, proto parser.Proto, cfg *conf.Config) error }
Generator defines a generator interface to describe how to generate rpc service
type RPCGenerator ¶
type RPCGenerator struct {
// contains filtered or unexported fields
}
RPCGenerator defines a generator and configure
func NewDefaultRPCGenerator ¶
func NewDefaultRPCGenerator(style string) (*RPCGenerator, error)
NewDefaultRPCGenerator wraps Generator with configure
func NewRPCGenerator ¶
func NewRPCGenerator(g Generator, cfg *conf.Config) *RPCGenerator
NewRPCGenerator creates an instance for RPCGenerator
func (*RPCGenerator) Generate ¶
func (g *RPCGenerator) Generate(src, target string, protoImportPath []string) error
Generate generates an 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