Documentation ¶
Overview ¶
Package protogenutil provides support for protoc plugin development with the appproto and protogen packages.
Index ¶
- func GetFieldGoType(generatedFile *protogen.GeneratedFile, field *protogen.Field) (string, error)
- func GetFieldGoZeroValue(generatedFile *protogen.GeneratedFile, field *protogen.Field) (string, error)
- func GetParameterErrorReturnString(generatedFile *protogen.GeneratedFile, fields []*protogen.Field, ...) (string, error)
- func GetParameterStrings(generatedFile *protogen.GeneratedFile, fields []*protogen.Field) ([]string, error)
- func GetUnexportGoName(goName string) string
- func NewFileHandler(f func(*protogen.Plugin, []*protogen.File) error, options ...HandlerOption) appproto.Handler
- func NewGoPackageHandler(f func(*protogen.Plugin, []*GoPackageFileSet) error, options ...HandlerOption) appproto.Handler
- func NewHandler(f func(*protogen.Plugin) error, options ...HandlerOption) appproto.Handler
- func NewNamedFileHandler(f func(NamedHelper, *protogen.Plugin, []*protogen.File) error) appproto.Handler
- func NewNamedGoPackageHandler(f func(NamedHelper, *protogen.Plugin, []*GoPackageFileSet) error) appproto.Handler
- func NewNamedPerFileHandler(f func(NamedHelper, *protogen.Plugin, *protogen.File) error) appproto.Handler
- func NewNamedPerGoPackageHandler(f func(NamedHelper, *protogen.Plugin, *GoPackageFileSet) error) appproto.Handler
- func NewPerFileHandler(f func(*protogen.Plugin, *protogen.File) error, options ...HandlerOption) appproto.Handler
- func NewPerGoPackageHandler(f func(*protogen.Plugin, *GoPackageFileSet) error, options ...HandlerOption) appproto.Handler
- func ProtoPackagePascalCase(protoPackage string) string
- func ValidateFieldNotMap(field *protogen.Field) error
- func ValidateFieldNotOneof(field *protogen.Field) error
- func ValidateMethodUnary(method *protogen.Method) error
- type GoPackageFileSet
- type HandlerOption
- type NamedHelper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetFieldGoType ¶
func GetFieldGoType( generatedFile *protogen.GeneratedFile, field *protogen.Field, ) (string, error)
GetFieldGoType returns the Go type used for a field.
Adapted from https://github.com/protocolbuffers/protobuf-go/blob/81d297c66c9b1e0606eee19a9ee718dcf149276d/cmd/protoc-gen-go/internal_gengo/main.go#L640 See https://github.com/protocolbuffers/protobuf-go/blob/81d297c66c9b1e0606eee19a9ee718dcf149276d/LICENSE for the license.
func GetFieldGoZeroValue ¶
func GetFieldGoZeroValue( generatedFile *protogen.GeneratedFile, field *protogen.Field, ) (string, error)
GetFieldGoZeroValue returns the go zero value for a field.
func GetParameterErrorReturnString ¶
func GetParameterErrorReturnString( generatedFile *protogen.GeneratedFile, fields []*protogen.Field, errorVarName string, ) (string, error)
GetParameterErrorReturnString gets the return string for an error for a method.
func GetParameterStrings ¶
func GetParameterStrings( generatedFile *protogen.GeneratedFile, fields []*protogen.Field, ) ([]string, error)
GetParameterStrings gets the parameters for the given fields.
func GetUnexportGoName ¶
GetUnexportGoName returns a new unexported type for the go name.
This makes the first character lowercase. If the goName is empty, this returns empty.
func NewFileHandler ¶
func NewFileHandler(f func(*protogen.Plugin, []*protogen.File) error, options ...HandlerOption) appproto.Handler
NewFileHandler returns a newHandler for the protogen file function.
This will invoke f with every file marked for generation.
func NewGoPackageHandler ¶
func NewGoPackageHandler(f func(*protogen.Plugin, []*GoPackageFileSet) error, options ...HandlerOption) appproto.Handler
NewGoPackageHandler returns a newHandler for the protogen package function.
This validates that all files marked for generation that would be generated to the same directory also have the same go package and go import path.
This will invoke f with every file marked for generation.
func NewHandler ¶
NewHandler returns a new appproto.Handler for the protogen.Plugin function.
func NewNamedFileHandler ¶
func NewNamedFileHandler(f func(NamedHelper, *protogen.Plugin, []*protogen.File) error) appproto.Handler
NewNamedFileHandler returns a new file handler for a named plugin.
func NewNamedGoPackageHandler ¶
func NewNamedGoPackageHandler(f func(NamedHelper, *protogen.Plugin, []*GoPackageFileSet) error) appproto.Handler
NewNamedGoPackageHandler returns a new go package handler for a named plugin.
func NewNamedPerFileHandler ¶
func NewNamedPerFileHandler(f func(NamedHelper, *protogen.Plugin, *protogen.File) error) appproto.Handler
NewNamedPerFileHandler returns a new per-file handler for a named plugin.
func NewNamedPerGoPackageHandler ¶
func NewNamedPerGoPackageHandler(f func(NamedHelper, *protogen.Plugin, *GoPackageFileSet) error) appproto.Handler
NewNamedPerGoPackageHandler returns a new per-go-package handler for a named plugin.
func NewPerFileHandler ¶
func NewPerFileHandler(f func(*protogen.Plugin, *protogen.File) error, options ...HandlerOption) appproto.Handler
NewPerFileHandler returns a newHandler for the protogen per-file function.
This will invoke f for every file marked for generation.
func NewPerGoPackageHandler ¶
func NewPerGoPackageHandler(f func(*protogen.Plugin, *GoPackageFileSet) error, options ...HandlerOption) appproto.Handler
NewPerGoPackageHandler returns a newHandler for the protogen per-package function.
This validates that all files marked for generation that would be generated to the same directory also have the same go package and go import path.
This will invoke f for every file marked for generation.
func ProtoPackagePascalCase ¶
ProtoPackagePascalCase converts a package in the form foo.bar.baz to FooBarBaz.
func ValidateFieldNotMap ¶
ValidateFieldNotMap validates that the field is not a map.
func ValidateFieldNotOneof ¶
ValidateFieldNotOneof validates that the field is not a oneof.
func ValidateMethodUnary ¶
ValidateMethodUnary validates that the method is unary.
Types ¶
type GoPackageFileSet ¶
type GoPackageFileSet struct { // The directory the golang/protobuf files would be generated to. GeneratedDir string // The Go import path the golang/protobuf files would be generated to. GoImportPath protogen.GoImportPath // The Go package name the golang/protobuf files would be generated to. GoPackageName protogen.GoPackageName // ProtoPackage is the proto package for all files. ProtoPackage string // The files within this package that are marked for generate. Files []*protogen.File }
GoPackageFileSet are files within a single Go package.
func (*GoPackageFileSet) Services ¶
func (g *GoPackageFileSet) Services() []*protogen.Service
Services returns all the services in this Go package sorted by Go name.
type HandlerOption ¶
type HandlerOption func(*handlerOptions)
HandlerOption is an option for a new Handler.
func HandlerWithOptionHandler ¶
func HandlerWithOptionHandler(optionHandler func(string, string) error) HandlerOption
HandlerWithOptionHandler returns a new HandlerOption that sets the given param function.
This parses options given on the command line.
type NamedHelper ¶
type NamedHelper interface { // NewGoPackageName gets the helper GoPackageName for the pluginName. NewGoPackageName( baseGoPackageName protogen.GoPackageName, pluginName string, ) protogen.GoPackageName // NewGoImportPath gets the helper GoImportPath for the pluginName. NewGoImportPath( file *protogen.File, pluginName string, ) (protogen.GoImportPath, error) // NewPackageGoImportPath gets the helper GoImportPath for the pluginName. NewPackageGoImportPath( goPackageFileSet *GoPackageFileSet, pluginName string, ) (protogen.GoImportPath, error) // NewGlobalImportPath gets the helper GoImportPath for the pluginName. NewGlobalGoImportPath( pluginName string, ) (protogen.GoImportPath, error) // NewGeneratedFile returns a new individual GeneratedFile for a named plugin. // // This should be used for named plugins that have a 1-1 mapping between Protobuf files // and generated files. // // This also prints the file header and package. NewGeneratedFile( plugin *protogen.Plugin, file *protogen.File, pluginName string, ) (*protogen.GeneratedFile, error) // NewPackageGeneratedFile returns a new individual GeneratedFile for a named plugin. // // This should be used for named plugins that have a 1-1 mapping between Protobuf files // and generated files. The generated file name will not overlap with the base name // of any .proto file in the package. // // This also prints the file header and package. NewPackageGeneratedFile( plugin *protogen.Plugin, goPackageFileSet *GoPackageFileSet, pluginName string, ) (*protogen.GeneratedFile, error) // NewGlobalGeneratedFile returns a new global GeneratedFile for a named plugin. // // This also prints the file header and package. NewGlobalGeneratedFile( plugin *protogen.Plugin, pluginName string, ) (*protogen.GeneratedFile, error) }
NamedHelper is a helper to deal with named golang plugins.
Named plugins should be named in the form protoc-gen-go-foobar, where the plugin name is consiered to be "foobar". The plugin name must be lowercase.