retag

package
v0.0.0-...-c204959 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2017 License: BSD-3-Clause Imports: 8 Imported by: 0

README

retag

a plugin for protoc-gen-go to reset struct tags.

why

golang protobuf doesn't support custom tags to generated structs. this plugin help to set custom tags to generated protobuf file.

install

git clone https://github.com/qianlnk/protobuf.git $GOPATH/src/github.com/golang/protobuf
go install $GOPATH/src/github.com/golang/protobuf/protoc-gen-go

usage

Add a comment with syntax //`custom_tag1:custom_value1 custom_tag2:custom_value2` after fields.

Example:

syntax = "proto3";

package staff;

message Staff {
    string ID = 1;    //`json:"id,omitempty"   xml:"id,omitempty"`
    string Name = 2;  //`json:"name,omitempty" xml:"name,omitempty"`
    int64 Age = 3;    //`json:"age,omitempty"  xml:"age,omitempty"`
}

generate .pb.go with command protoc as:

protoc --go_out=plugins=grpc+retag:. example.proto

the custom tag will set to strcut:

type Staff struct {
    ID   string `protobuf:"bytes,1,opt,name=ID"     json:"id,omitempty"    xml:"id,omitempty"`
    Name string `protobuf:"bytes,2,opt,name=Name"   json:"name,omitempty"  xml:"name,omitempty"`
    Age  int64  `protobuf:"varint,3,opt,name=Age"   json:"age,omitempty"   xml:"age,omitempty"`
}

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package staff is a generated protocol buffer package.
Package staff is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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