protogenutil

package
v1.0.0-rc4 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package protogenutil provides support for protoc plugin development with the appproto and protogen packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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

func GetUnexportGoName(goName string) string

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

func NewHandler(f func(*protogen.Plugin) error, options ...HandlerOption) appproto.Handler

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

func ProtoPackagePascalCase(protoPackage string) string

ProtoPackagePascalCase converts a package in the form foo.bar.baz to FooBarBaz.

func ValidateFieldNotMap

func ValidateFieldNotMap(field *protogen.Field) error

ValidateFieldNotMap validates that the field is not a map.

func ValidateFieldNotOneof

func ValidateFieldNotOneof(field *protogen.Field) error

ValidateFieldNotOneof validates that the field is not a oneof.

func ValidateMethodUnary

func ValidateMethodUnary(method *protogen.Method) error

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.

Jump to

Keyboard shortcuts

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