Giter Site home page Giter Site logo

protopatch's Introduction

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

protopatch's People

Contributors

ydnar avatar connyay avatar adphi avatar dependabot[bot] avatar moul avatar altaci avatar

Stargazers

Roman avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.