patch

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunPlugin

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.

func Write

Write marshals and writes CodeGeneratorResponse res to w.

Types

type Package

type Package struct {
	// contains filtered or unexported fields
}

Package represents a Go package for patching.

func NewPackage

func NewPackage(path, name string) *Package

NewPackage returns an initialized Package.

func (*Package) AddFile

func (pkg *Package) AddFile(filename string, f *ast.File) error

AddFile adds a parsed file to pkg.

func (*Package) Check

func (pkg *Package) Check(importer types.Importer, fset *token.FileSet, info *types.Info) error

Check type-checks pkg.

func (*Package) File

func (pkg *Package) File(filename string) *ast.File

File returns the ast.File for filename, if it exists.

func (*Package) Find

func (pkg *Package) Find(id protogen.GoIdent) (obj types.Object, ancestors []types.Object)

Find finds id in Package pkg, and any ancestor(s), or nil if the id is not found in pkg.

func (*Package) Reset

func (pkg *Package) Reset()

Reset resets pkg type-checks.

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

func NewPatcher(gen *protogen.Plugin) (*Patcher, error)

NewPatcher returns an initialized Patcher for gen.

func (*Patcher) Patch

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

func (p *Patcher) RenameField(id protogen.GoIdent, newName string)

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

func (p *Patcher) RenameMethod(id protogen.GoIdent, newName string)

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

func (p *Patcher) RenameType(id protogen.GoIdent, newName string)

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

func (p *Patcher) RenameValue(id protogen.GoIdent, newName string)

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

func (p *Patcher) Tag(id protogen.GoIdent, tags string)

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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