com

package
v0.0.0-...-d853fe5 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 AStringContains

func AStringContains(s []string, n string) bool

AStringContains 判断字符串数组中是否包含某个字符串

@param s 数组
@param n 字符串
@return bool

func Add

func Add(num1, num2 int) int

Add add two number

func Camelcase

func Camelcase(s string) string

Camelcase 驼峰处理,特殊case要兼容存量协议,否则转驼峰命名

func CamelcaseList

func CamelcaseList(wordList []string) string

CamelcaseList 驼峰处理字符串列表,最后输出一个字符串结果

func CheckSECVTpl

func CheckSECVTpl(pkgMap map[string]string) bool

CheckSECVTpl 检查是否启用Validation特性,来决定导出的模板内容

func Concat

func Concat(sep string, s ...string) string

Concat 连接字符串

func FieldType

func FieldType(f *protogen.Field, myGoImportPath string) string

func FileName

func FileName(fullFileName string) string

func GoCamelCase

func GoCamelCase(s string) string

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 GoCamelCaseModel

func GoCamelCaseModel(s string) string

GoCamelCaseModel TODO

func GoComments

func GoComments(name string, comments protogen.CommentSet) string

GoComments TODO

func GoExistImportPaths

func GoExistImportPaths(is []rewrite.Import, alias, path string) bool

GoExistImportPaths 判断import是不是存在

@param rw
@param fileName
@return []rewrite.Import

func GoExport

func GoExport(typ string) string

GoExport export go type

func GoGetImportPaths

func GoGetImportPaths(rw *rewrite.Rewriter, fileName string) []rewrite.Import

GoGetImportPaths 获取import列表

@param rw
@param fileName
@return []rewrite.Import

func GoGetMethodBody

func GoGetMethodBody(rw *rewrite.Rewriter, structname, methodName string) string

GoGetMethodBody 获取函数已实现的函数体

@param rw
@param structname
@param methodName
@return string

func HasBBQFieldTag

func HasBBQFieldTag(m *protogen.Message) bool

func HasPrefix

func HasPrefix(prefix, str string) bool

HasPrefix test whether string `str` has prefix `prefix`

func HasSuffix

func HasSuffix(suffix, str string) bool

HasSuffix test whether string `str` has suffix `suffix`

func IsService

func IsService(s *Service) bool

func Last

func Last(list []string) string

Last returns the last element in `list`

func PBGoPackage

func PBGoPackage(pkgName string) string

PBGoPackage convert a.b.c to a_b_c

func PBGoType

func PBGoType(t string) string

PBGoType convert `t` to go style (like a.b.c.hello, it'll be changed to a_b_c.Hello)

func PBSimplifyGoType

func PBSimplifyGoType(fullTypeName string, goPackageName string) string

PBSimplifyGoType determine whether to use fullyQualifiedPackageName or not, if the `fullTypeName` occur in code of `package goPackageName`, `package` part should be removed.

func PBValidGoPackage

func PBValidGoPackage(pkgName string) string

PBValidGoPackage return valid go package

func SplitList

func SplitList(str, sep string) []string

SplitList split string `str` via delimiter `sep` into a list of string

func Title

func Title(s string) string

Title uppercase the first character of `s`

func TplSuffix

func TplSuffix(name string) string

TplSuffix eg main.grpc.go.tpl -> .grpc.go

@param name
@return string

func TrimLeft

func TrimLeft(str, sep string) string

TrimLeft trim left substr starting at `sep`

func TrimRight

func TrimRight(str, sep string) string

TrimRight trim right substr starting at `sep`

func UnTitle

func UnTitle(s string) string

UnTitle make the first character of s lowercase

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 Generator

type Generator interface {

	// Generate code
	Generate(tplPath string, proto *Proto) error
}

Generator generate code

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

Directories

Path Synopsis
gorewriter

Jump to

Keyboard shortcuts

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