protopatch

module
v0.0.0-...-b7b212d Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2020 License: MIT

README

protopatch

Patch protoc plugin output with Go-specific features. The protoc-gen-go-patch command wraps calls to Go code generators like protoc-gen-go or protoc-gen-go-grpc and patches the Go syntax before being written to disk.

Features

Patches are defined via an Options extension on messages, fields, oneof fields, enums, and enum values.

  • go.message — message options, which modify the generated Go struct for a message.
  • go.field — message field options, which modify Go struct fields and getter methods.
  • go.oneofoneof field options, which modify struct fields, interface types, and wrapper types.
  • go.enumenum options, which modify Go enum types and values.
  • go.valueenum value options, which modify Go const values.
Custom Names
import "patch/go.proto";

message OldName {
	option (go.message) = {name: 'NewName'};
	int id = 1 [(go.field) = {name: 'ID'}];
}

enum Errors {
	option (go.enum) = {name: 'ProtocolErrors'};
	INVALID = 1 [(go.value) = {name: 'ErrInvalid'}];
	NOT_FOUND = 2 [(go.value) = {name: 'ErrNotFound'}];
	TOO_FUN = 3 [(go.value) = {name: 'ErrTooFun'}];
}
Struct Tags
message ToDo {
	int32 id = 1 [(go.field) = {name: 'ID', tags: '`xml:"id,attr"`'}];
	string description = 2 [(go.field) = {tags: '`xml:"desc"`'}];
}
TODO: More Documentation

Install

go install github.com/alta/protopatch/cmd/protoc-gen-go-patch

Usage

After installing protoc-gen-go-patch, use it by specifying it with a --go-patch_out=... argument to protoc:

protoc \
	-I . \
	-I `go list -m -f {{.Dir}} github.com/alta/protopatch` \
	-I `go list -m -f {{.Dir}} google.golang.org/protobuf` \
	--go-patch_out=plugin=go,paths=source_relative:. \
	--go-patch_out=plugin=go-grpc,paths=source_relative:. \
	*.proto

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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