Documentation ¶
Index ¶
- func RunPlugin(plugin string, req *pluginpb.CodeGeneratorRequest, stderr io.Writer) (*pluginpb.CodeGeneratorResponse, error)
- func StripParam(req *pluginpb.CodeGeneratorRequest, p string)
- func Write(res *pluginpb.CodeGeneratorResponse, w io.Writer) error
- type Package
- func (pkg *Package) AddFile(filename string, f *ast.File) error
- func (pkg *Package) Check(importer types.Importer, fset *token.FileSet, info *types.Info) error
- func (pkg *Package) File(filename string) *ast.File
- func (pkg *Package) Find(id protogen.GoIdent) (obj types.Object, ancestors []types.Object)
- func (pkg *Package) Reset()
- type Patcher
- func (p *Patcher) Patch(res *pluginpb.CodeGeneratorResponse) error
- func (p *Patcher) RenameField(id protogen.GoIdent, newName string)
- func (p *Patcher) RenameMethod(id protogen.GoIdent, newName string)
- func (p *Patcher) RenameType(id protogen.GoIdent, newName string)
- func (p *Patcher) RenameValue(id protogen.GoIdent, newName string)
- func (p *Patcher) Tag(id protogen.GoIdent, tags string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RunPlugin ¶
func RunPlugin(plugin string, req *pluginpb.CodeGeneratorRequest, stderr io.Writer) (*pluginpb.CodeGeneratorResponse, error)
RunPlugin runs a protoc plugin named "protoc-gen-$plugin" and returns the generated CodeGeneratorResponse or an error. Supply a non-nil stderr to override stderr on the called plugin.
func StripParam ¶
func StripParam(req *pluginpb.CodeGeneratorRequest, p string)
StripParam strips a named param from req.
Types ¶
type Package ¶
type Package struct {
// contains filtered or unexported fields
}
Package represents a Go package for patching.
func NewPackage ¶
NewPackage returns an initialized Package.
type Patcher ¶
type Patcher struct {
// contains filtered or unexported fields
}
Patcher patches a set of generated Go Protobuf files with additional features: - go_name (Field option) overrides the name of a synthesized struct field and getters. - go_tags (Field option) lets you add additional struct tags to a field. - go_oneof_name (Oneof option) overrides the name of a oneof field, including wrapper types and getters. - go_oneof_tags (Oneof option) lets you specify additional struct tags on a oneof field. - go_message_name (Message option) overrides the name of the synthesized struct. - go_enum_name (Enum option) overrides the name of an enum type. - go_value_name (EnumValue option) overrides the name of an enum const.
func NewPatcher ¶
NewPatcher returns an initialized Patcher for gen.
func (*Patcher) Patch ¶
func (p *Patcher) Patch(res *pluginpb.CodeGeneratorResponse) error
Patch applies the patch(es) in p the Go files in res. Clone res before calling Patch if you want to retain an unmodified copy. The behavior of calling Patch multiple times is currently undefined.
func (*Patcher) RenameField ¶
RenameField renames the Go struct field specified by id to newName. The id argument specifies a GoName from GoImportPath, e.g.: "github.com/org/repo/example".FooMessage.BarField newName should be the unqualified name (after the dot). The value of id.GoName should be the original generated identifier name, not a renamed identifier.
func (*Patcher) RenameMethod ¶
RenameMethod renames the Go struct or interface method specified by id to newName. The id argument specifies a GoName from GoImportPath, e.g.: "github.com/org/repo/example".FooMessage.GetBarField The new name should be the unqualified name (after the dot). The value of id.GoName should be the original generated identifier name, not a renamed identifier.
func (*Patcher) RenameType ¶
RenameType renames the Go type specified by id to newName. The id argument specifies a GoName from GoImportPath, e.g.: "github.com/org/repo/example".FooMessage To rename a package-level identifier such as a type, var, or const, specify just the name, e.g. "Message" or "Enum_VALUE". newName should be the unqualified name. The value of id.GoName should be the original generated type name, not a renamed type.
func (*Patcher) RenameValue ¶
RenameValue renames the Go value (const or var) specified by id to newName. The id argument specifies a GoName from GoImportPath, e.g.: "github.com/org/repo/example".FooValue newName should be the unqualified name. The value of id.GoName should be the original generated type name, not a renamed type.
func (*Patcher) Tag ¶
Tag adds the specified struct tags to the field specified by selector, in the form of "Message.Field". The tags argument should omit outer backticks (`). The value of id.GoName should be the original generated identifier name, not a renamed identifier. The struct tags will be applied when Patch is called.