Documentation ¶
Index ¶
- Variables
- func AStringContains(s []string, n string) bool
- func Add(num1, num2 int) int
- func Camelcase(s string) string
- func CamelcaseList(wordList []string) string
- func CheckSECVTpl(pkgMap map[string]string) bool
- func Concat(sep string, s ...string) string
- func FieldType(f *protogen.Field, myGoImportPath string) string
- func FileName(fullFileName string) string
- func GoCamelCase(s string) string
- func GoCamelCaseModel(s string) string
- func GoComments(name string, comments protogen.CommentSet) string
- func GoExistImportPaths(is []rewrite.Import, alias, path string) bool
- func GoExport(typ string) string
- func GoGetImportPaths(rw *rewrite.Rewriter, fileName string) []rewrite.Import
- func GoGetMethodBody(rw *rewrite.Rewriter, structname, methodName string) string
- func HasBBQFieldTag(m *protogen.Message) bool
- func HasPrefix(prefix, str string) bool
- func HasSuffix(suffix, str string) bool
- func IsService(s *Service) bool
- func Last(list []string) string
- func PBGoPackage(pkgName string) string
- func PBGoType(t string) string
- func PBSimplifyGoType(fullTypeName string, goPackageName string) string
- func PBValidGoPackage(pkgName string) string
- func SplitList(str, sep string) []string
- func Title(s string) string
- func TplSuffix(name string) string
- func TrimLeft(str, sep string) string
- func TrimRight(str, sep string) string
- func UnTitle(s string) string
- type File
- type Generator
- type Method
- type Proto
- type Service
Constants ¶
This section is empty.
Variables ¶
var FuncMap = template.FuncMap{ "goComments": GoComments, "goCamelcase": GoCamelCase, "goCamelcaseType": GoCamelCaseModel, "goGetMethodBody": GoGetMethodBody, "goGetImportPaths": GoGetImportPaths, "goExistImportPaths": GoExistImportPaths, "gopkg": PBGoPackage, "gopkgSimple": PBValidGoPackage, "goType": PBGoType, "export": GoExport, "simplify": PBSimplifyGoType, "FileName": FileName, "FieldType": FieldType, "HasBBQFieldTag": HasBBQFieldTag, "camelcase": Camelcase, "lowerCamelcase": strcase.ToLowerCamel, "title": Title, "untitle": UnTitle, "trimright": TrimRight, "trimleft": TrimLeft, "splitList": SplitList, "last": Last, "hasPrefix": HasPrefix, "hasSuffix": HasSuffix, "contains": strings.Contains, "add": Add, "lower": strings.ToLower, "snakecase": strcase.ToSnake, "replace": strings.ReplaceAll, "concat": Concat, "isService": IsService, }
FuncMap 模版中使用的函数列表
Functions ¶
func CamelcaseList ¶
CamelcaseList 驼峰处理字符串列表,最后输出一个字符串结果
func CheckSECVTpl ¶
CheckSECVTpl 检查是否启用Validation特性,来决定导出的模板内容
func GoCamelCase ¶
GoCamelCase camel-cases a protobuf name for use as a Go identifier.
If there is an interior underscore followed by a lower case letter, drop the underscore and convert the letter to upper case.
func GoExistImportPaths ¶
GoExistImportPaths 判断import是不是存在
@param rw @param fileName @return []rewrite.Import
func GoGetImportPaths ¶
GoGetImportPaths 获取import列表
@param rw @param fileName @return []rewrite.Import
func GoGetMethodBody ¶
GoGetMethodBody 获取函数已实现的函数体
@param rw @param structname @param methodName @return string
func HasBBQFieldTag ¶
func PBGoType ¶
PBGoType convert `t` to go style (like a.b.c.hello, it'll be changed to a_b_c.Hello)
func PBSimplifyGoType ¶
PBSimplifyGoType determine whether to use fullyQualifiedPackageName or not, if the `fullTypeName` occur in code of `package goPackageName`, `package` part should be removed.
func PBValidGoPackage ¶
PBValidGoPackage return valid go package
Types ¶
type File ¶
type File struct { Name *string // file name, relative to root of source tree Package *string // e.g. "foo", "foo.bar", etc. // Names of files imported by this file. Dependency []string // Indexes of the public imported files in the dependency list above. PublicDependency []int32 // Indexes of the weak imported files in the dependency list. // For Google-internal migration only. Do not use. WeakDependency []int32 Options *descriptorpb.FileOptions // This field contains optional information about the original source code. // You may safely remove this entire field without harming runtime // functionality of the descriptors -- the information is needed only by // development tools. SourceCodeInfo *descriptorpb.SourceCodeInfo // The syntax of the proto file. // The supported values are "proto2" and "proto3". Syntax *string Desc protoreflect.FileDescriptor // Go GoImplPackage string // 实现本PB协议的package GoDescriptorIdent protogen.GoIdent // name of Go variable for the file descriptor GoPackageName string // name of this file's Go package GoImportPath string // import path of this file's Go package GoImplImportPaths []rewrite.Import // import path of this impelement file's Go package GoRewriter *rewrite.Rewriter Enums []*protogen.Enum // top-level enum declarations Messages []*protogen.Message // top-level message declarations Extensions []*protogen.Extension // top-level extension declarations Services []*Service // top-level service declarations Generate bool // true if we should generate code for this file // GeneratedFilenamePrefix is used to construct filenames for generated // files associated with this source file. // // For example, the source file "dir/foo.proto" might have a filename prefix // of "dir/foo". Appending ".pb.go" produces an output file of "dir/foo.pb.go". GeneratedFilenamePrefix string }
File DescriptorProto Describes a complete .proto file. https://pkg.go.dev/google.golang.org/protobuf/types/descriptorpb#FileDescriptorProto
type Method ¶
type Method struct { Name *string // Input and output type names. These are resolved in the same way as // FieldDescriptorProto.type_name, but must refer to a message type. InputType *string OutputType *string Options *descriptorpb.MethodOptions // Identifies if client streams multiple client messages ClientStreaming *bool // Identifies if server streams multiple server messages ServerStreaming *bool Desc protoreflect.MethodDescriptor // Go GoName string GoInput *protogen.Message GoOutput *protogen.Message HasResponse bool Location protogen.Location // location of this method Comments protogen.CommentSet // comments associated with this method }
Method DescriptorProto Describes a method of a service. google.golang.org/protobuf/types/descriptorpb.MethodDescriptorProto
type Proto ¶
type Proto struct { // https://pkg.go.dev/google.golang.org/protobuf@v1.27.1/compiler/protogen#Options.Run Plugin *protogen.Plugin // All proto file descriptor Files []*File // .all.tpl 才会有 GoRewriter *rewrite.Rewriter }
Proto is An encoded CodeGeneratorRequest is written to the plugin's stdin. https://pkg.go.dev/google.golang.org/protobuf/types/pluginpb#CodeGeneratorRequest
type Service ¶
type Service struct { Name *string Options *descriptorpb.ServiceOptions Desc protoreflect.ServiceDescriptor HasHTTPOption bool // Go GoName string Methods []*Method // service method declarations Location protogen.Location // location of this service Comments protogen.CommentSet // comments associated with this service }
Service DescriptorProto Describes a service. google.golang.org/protobuf/types/descriptorpb.ServiceDescriptorProto