├── module ├── test │ ├── input.txt │ └── golden.txt ├── tagger.go ├── replace_test.go ├── extract.go └── replace.go ├── .gitignore ├── main.go ├── tagger ├── tagger.proto └── tagger.pb.go ├── Makefile ├── example ├── example.proto └── example.pb.go ├── LICENSE └── README.md /module/test/input.txt: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | type Simple struct { 4 | Single string `json:"key,option"` 5 | Multiple string `json:"ke,op" xml:"ke,op"` 6 | None int32 7 | } 8 | -------------------------------------------------------------------------------- /module/test/golden.txt: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | type Simple struct { 4 | Single string `json:"key,option" sql:"-,omitempty"` 5 | Multiple string `json:"ke,op" xml:"-,omitempty"` 6 | None int32 `json:"none,omitempty"` 7 | } 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, build with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | .idea/ 14 | .vscode/ -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | pgs "github.com/lyft/protoc-gen-star" 5 | pgsgo "github.com/lyft/protoc-gen-star/lang/go" 6 | 7 | "github.com/amsokol/protoc-gen-gotag/module" 8 | ) 9 | 10 | func main() { 11 | pgs.Init(pgs.DebugEnv("DEBUG")). 12 | RegisterModule(module.New()). 13 | RegisterPostProcessor(pgsgo.GoFmt()). 14 | Render() 15 | } 16 | -------------------------------------------------------------------------------- /tagger/tagger.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package tagger; 4 | 5 | import "google/protobuf/descriptor.proto"; 6 | 7 | option go_package = "github.com/amsokol/protoc-gen-gotag/tagger;tagger"; 8 | 9 | // Tags are applied at the field level 10 | extend google.protobuf.FieldOptions { 11 | // Multiple Tags can be spcified. 12 | string tags = 847939; 13 | } 14 | 15 | extend google.protobuf.OneofOptions { 16 | // Multiple Tags can be spcified. 17 | string oneof_tags = 847939; 18 | } -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | LOCAL_PATH = $(shell pwd) 2 | 3 | .PHONY: example proto install gen-tag test 4 | 5 | example: proto install 6 | protoc -I /usr/local/include \ 7 | -I ${LOCAL_PATH} \ 8 | --gotag_out=xxx="graphql+\"-\" bson+\"-\"":. example/example.proto 9 | 10 | proto: 11 | protoc -I /usr/local/include \ 12 | -I ${LOCAL_PATH} \ 13 | --go_out=:. example/example.proto 14 | 15 | install: 16 | go install . 17 | 18 | gen-tag: 19 | protoc -I /usr/local/include \ 20 | -I ${LOCAL_PATH} \ 21 | --go_out=paths=source_relative:. tagger/tagger.proto 22 | 23 | test: 24 | go test ./... -------------------------------------------------------------------------------- /example/example.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package example; 4 | 5 | import "tagger/tagger.proto"; 6 | 7 | message Example { 8 | string with_new_tags = 1 [(tagger.tags) = "graphql:\"withNewTags,optional\"" ]; 9 | string with_new_multiple = 2 [(tagger.tags) = "graphql:\"withNewTags,optional\" xml:\"multi,omitempty\"" ]; 10 | 11 | string replace_default = 3 [(tagger.tags) = "json:\"replacePrevious\""] ; 12 | 13 | oneof one_of { 14 | option (tagger.oneof_tags) = "graphql:\"withNewTags,optional\""; 15 | string a = 5 [(tagger.tags) = "json:\"A\""]; 16 | int32 b_jk = 6 [(tagger.tags) = "json:\"b_Jk\""]; 17 | } 18 | } 19 | 20 | message SecondMessage { 21 | string with_new_tags = 1 [(tagger.tags) = "graphql:\"withNewTags,optional\"" ]; 22 | string with_new_multiple = 2 [(tagger.tags) = "graphql:\"withNewTags,optional\" xml:\"multi,omitempty\"" ]; 23 | 24 | string replace_default = 3 [(tagger.tags) = "json:\"replacePrevious\""] ; 25 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Sri Krishna Paritala 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /module/tagger.go: -------------------------------------------------------------------------------- 1 | package module 2 | 3 | import ( 4 | "go/parser" 5 | "go/printer" 6 | "go/token" 7 | "strings" 8 | 9 | "github.com/fatih/structtag" 10 | pgs "github.com/lyft/protoc-gen-star" 11 | pgsgo "github.com/lyft/protoc-gen-star/lang/go" 12 | ) 13 | 14 | type mod struct { 15 | *pgs.ModuleBase 16 | ctx pgsgo.Context 17 | } 18 | 19 | func New() pgs.Module { 20 | return &mod{ModuleBase: &pgs.ModuleBase{}} 21 | } 22 | 23 | func (m *mod) InitContext(c pgs.BuildContext) { 24 | m.ModuleBase.InitContext(c) 25 | m.ctx = pgsgo.InitContext(c.Parameters()) 26 | } 27 | 28 | func (m *mod) Name() string { 29 | return "gotag" 30 | } 31 | 32 | func (m *mod) Execute(targets map[string]pgs.File, packages map[string]pgs.Package) []pgs.Artifact { 33 | xtv := m.Parameters().Str("xxx") 34 | xtv = strings.Replace(xtv, "+", ":", -1) 35 | xt, err := structtag.Parse(xtv) 36 | m.CheckErr(err) 37 | 38 | extractor := newTagExtractor(m) 39 | for _, f := range targets { 40 | tags := extractor.Extract(f) 41 | 42 | tags.AddTagsToXXXFields(xt) 43 | 44 | gfname := m.BuildContext.JoinPath(f.InputPath().SetExt(".pb.go").Base()) 45 | 46 | fs := token.NewFileSet() 47 | fn, err := parser.ParseFile(fs, gfname, nil, parser.ParseComments) 48 | m.CheckErr(err) 49 | 50 | m.CheckErr(Retag(fn, tags)) 51 | 52 | var buf strings.Builder 53 | m.CheckErr(printer.Fprint(&buf, fs, fn)) 54 | 55 | m.OverwriteGeneratorFile(gfname, buf.String()) 56 | } 57 | 58 | return m.Artifacts() 59 | } 60 | -------------------------------------------------------------------------------- /module/replace_test.go: -------------------------------------------------------------------------------- 1 | package module_test 2 | 3 | import ( 4 | "bytes" 5 | "flag" 6 | "go/parser" 7 | "go/printer" 8 | "go/token" 9 | "io" 10 | "io/ioutil" 11 | "os" 12 | "testing" 13 | 14 | "github.com/fatih/structtag" 15 | "github.com/amsokol/protoc-gen-gotag/module" 16 | ) 17 | 18 | var replaceOut = flag.Bool("tag-rep", false, "") 19 | 20 | func TestRetag(t *testing.T) { 21 | fs := token.NewFileSet() 22 | 23 | n, err := parser.ParseFile(fs, "./test/input.txt", nil, parser.ParseComments) 24 | if err != nil { 25 | t.Fatal(err) 26 | } 27 | 28 | module.Retag(n, map[string]map[string]*structtag.Tags{ 29 | "Simple": map[string]*structtag.Tags{ 30 | "Single": tagMust(structtag.Parse(`sql:"-,omitempty"`)), 31 | "Multiple": tagMust(structtag.Parse(`xml:"-,omitempty"`)), 32 | "None": tagMust(structtag.Parse(`json:"none,omitempty"`)), 33 | }, 34 | }) 35 | 36 | var buf bytes.Buffer 37 | if err := printer.Fprint(&buf, fs, n); err != nil { 38 | t.Fatal(err) 39 | } 40 | 41 | if *replaceOut { 42 | f, err := os.Create("./test/golden.txt") 43 | if err != nil { 44 | t.Fatal(err) 45 | } 46 | defer f.Close() 47 | 48 | if _, err := io.Copy(f, &buf); err != nil { 49 | t.Fatal(err) 50 | } 51 | 52 | return 53 | } 54 | 55 | out, err := ioutil.ReadFile("./test/golden.txt") 56 | if err != nil { 57 | t.Fatal(err) 58 | } 59 | 60 | if !bytes.Equal(out, buf.Bytes()) { 61 | t.Error("output doesnot match golden file") 62 | } 63 | } 64 | 65 | func tagMust(t *structtag.Tags, err error) *structtag.Tags { 66 | if err != nil { 67 | panic(err) 68 | } 69 | return t 70 | } 71 | -------------------------------------------------------------------------------- /module/extract.go: -------------------------------------------------------------------------------- 1 | package module 2 | 3 | import ( 4 | "github.com/amsokol/protoc-gen-gotag/tagger" 5 | "github.com/fatih/structtag" 6 | pgs "github.com/lyft/protoc-gen-star" 7 | ) 8 | 9 | type tagExtractor struct { 10 | pgs.Visitor 11 | pgs.DebuggerCommon 12 | 13 | tags map[string]map[string]*structtag.Tags 14 | } 15 | 16 | func newTagExtractor(d pgs.DebuggerCommon) *tagExtractor { 17 | v := &tagExtractor{DebuggerCommon: d} 18 | v.Visitor = pgs.PassThroughVisitor(v) 19 | return v 20 | } 21 | 22 | func (v *tagExtractor) VisitOneOf(o pgs.OneOf) (pgs.Visitor, error) { 23 | var tval string 24 | ok, err := o.Extension(tagger.E_OneofTags, &tval) 25 | if err != nil { 26 | return nil, err 27 | } 28 | 29 | if !ok { 30 | return v, nil 31 | } 32 | 33 | tags, err := structtag.Parse(tval) 34 | if err != nil { 35 | return nil, err 36 | } 37 | 38 | msgName := o.Message().Name().UpperCamelCase().String() 39 | 40 | if v.tags[msgName] == nil { 41 | v.tags[msgName] = map[string]*structtag.Tags{} 42 | } 43 | 44 | v.tags[msgName][o.Name().UpperCamelCase().String()] = tags 45 | 46 | return v, nil 47 | } 48 | 49 | func (v *tagExtractor) VisitField(f pgs.Field) (pgs.Visitor, error) { 50 | var tval string 51 | ok, err := f.Extension(tagger.E_Tags, &tval) 52 | if err != nil { 53 | return nil, err 54 | } 55 | 56 | msgName := f.Message().Name().UpperCamelCase().String() 57 | 58 | if f.InOneOf() { 59 | msgName = f.Message().Name().UpperCamelCase().String() + "_" + f.Name().UpperCamelCase().String() 60 | } 61 | 62 | if v.tags[msgName] == nil { 63 | v.tags[msgName] = map[string]*structtag.Tags{} 64 | } 65 | 66 | if ok { 67 | tags, err := structtag.Parse(tval) 68 | v.CheckErr(err) 69 | 70 | v.tags[msgName][f.Name().UpperCamelCase().String()] = tags 71 | } 72 | 73 | return v, nil 74 | } 75 | 76 | func (v *tagExtractor) Extract(f pgs.File) StructTags { 77 | v.tags = map[string]map[string]*structtag.Tags{} 78 | 79 | v.CheckErr(pgs.Walk(v, f)) 80 | 81 | return v.tags 82 | } 83 | -------------------------------------------------------------------------------- /module/replace.go: -------------------------------------------------------------------------------- 1 | package module 2 | 3 | import ( 4 | "go/ast" 5 | "go/token" 6 | "strings" 7 | 8 | "github.com/fatih/structtag" 9 | ) 10 | 11 | type StructTags map[string]map[string]*structtag.Tags 12 | 13 | func (s StructTags) AddTagsToXXXFields(tags *structtag.Tags) { 14 | xtags := map[string]*structtag.Tags{ 15 | "XXX_NoUnkeyedLiteral": tags, 16 | "XXX_unrecognized": tags, 17 | "XXX_sizecache": tags, 18 | } 19 | 20 | for o := range s { 21 | if s[o] == nil { 22 | s[o] = map[string]*structtag.Tags{} 23 | } 24 | 25 | for k, v := range xtags { 26 | s[o][k] = v 27 | } 28 | } 29 | } 30 | 31 | // Retag updates the existing tags with the map passed and modifies existing tags if any of the keys are matched. 32 | // First key to the tags argument is the name of the struct, the second key corresponds to field names. 33 | func Retag(n ast.Node, tags StructTags) error { 34 | r := retag{} 35 | f := func(n ast.Node) ast.Visitor { 36 | if r.err != nil { 37 | return nil 38 | } 39 | 40 | if tp, ok := n.(*ast.TypeSpec); ok { 41 | r.tags = tags[tp.Name.String()] 42 | return r 43 | } 44 | 45 | return nil 46 | } 47 | 48 | ast.Walk(structVisitor{f}, n) 49 | 50 | return r.err 51 | } 52 | 53 | type structVisitor struct { 54 | visitor func(n ast.Node) ast.Visitor 55 | } 56 | 57 | func (v structVisitor) Visit(n ast.Node) ast.Visitor { 58 | if tp, ok := n.(*ast.TypeSpec); ok { 59 | if _, ok := tp.Type.(*ast.StructType); ok { 60 | ast.Walk(v.visitor(n), n) 61 | return nil // This will ensure this struct is no longer traversed 62 | } 63 | } 64 | return v 65 | } 66 | 67 | type retag struct { 68 | err error 69 | tags map[string]*structtag.Tags 70 | } 71 | 72 | func (v retag) Visit(n ast.Node) ast.Visitor { 73 | if v.err != nil { 74 | return nil 75 | } 76 | 77 | if f, ok := n.(*ast.Field); ok { 78 | if len(f.Names) == 0 { 79 | return nil 80 | } 81 | newTags := v.tags[f.Names[0].String()] 82 | if newTags == nil { 83 | return nil 84 | } 85 | 86 | if f.Tag == nil { 87 | f.Tag = &ast.BasicLit{ 88 | Kind: token.STRING, 89 | } 90 | } 91 | 92 | oldTags, err := structtag.Parse(strings.Trim(f.Tag.Value, "`")) 93 | if err != nil { 94 | v.err = err 95 | return nil 96 | } 97 | 98 | for _, t := range newTags.Tags() { 99 | oldTags.Set(t) 100 | } 101 | 102 | f.Tag.Value = "`" + oldTags.String() + "`" 103 | 104 | return nil 105 | } 106 | 107 | return v 108 | } 109 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # protoc-gen-gotag (PGGT) 2 | 3 | PGGT is a protoc plugin used to add/replace struct tags on generated protobuf messages. 4 | Get it using `go get -u github.com/amsokol/protoc-gen-gotag` It supports the following features, 5 | 6 | ## Add/Replace Tags 7 | 8 | New tags like xml, sql, bson etc... can be added to struct messages of protobuf. Example 9 | 10 | ```proto 11 | syntax = "proto3"; 12 | 13 | package example; 14 | 15 | import "tagger/tagger.proto"; 16 | 17 | message Example { 18 | string with_new_tags = 1 [(tagger.tags) = "graphql:\"withNewTags,optional\"" ]; 19 | string with_new_multiple = 2 [(tagger.tags) = "graphql:\"withNewTags,optional\" xml:\"multi,omitempty\"" ]; 20 | 21 | string replace_default = 3 [(tagger.tags) = "json:\"replacePrevious\""] ; 22 | 23 | oneof one_of { 24 | option (tagger.oneof_tags) = "graphql:\"withNewTags,optional\""; 25 | string a = 5 [(tagger.tags) = "json:\"A\""]; 26 | int32 b_jk = 6 [(tagger.tags) = "json:\"b_Jk\""]; 27 | } 28 | } 29 | 30 | message SecondMessage { 31 | string with_new_tags = 1 [(tagger.tags) = "graphql:\"withNewTags,optional\"" ]; 32 | string with_new_multiple = 2 [(tagger.tags) = "graphql:\"withNewTags,optional\" xml:\"multi,omitempty\"" ]; 33 | 34 | string replace_default = 3 [(tagger.tags) = "json:\"replacePrevious\""] ; 35 | } 36 | ``` 37 | 38 | Then struct tags can be added by running this command **after** the regular protobuf generation command. 39 | 40 | ```bash 41 | protoc -I /usr/local/include \ 42 | -I . \ 43 | --gotag_out=output_path={OUTPUT-PATH}:. example/example.proto 44 | ``` 45 | 46 | In the above example tags like graphql and xml will be added whereas existing tags such as json are replaced with the supplied values. 47 | 48 | ## Add tags to XXX* fields 49 | 50 | It is very useful to ignore XXX* fields in protobuf generated messages. The go protocol buffer compiler adds ```json:"-"``` tag to all XXX* fields. Additional tags can be added to these fields using the 'xxx' option of PGGT. It can be done like this. All '+' characters will be replaced with ':'. 51 | 52 | ```bash 53 | protoc -I /usr/local/include \ 54 | -I . \ 55 | --gotag_out=xxx="graphql+\"-\" bson+\"-\"",output_path={OUTPUT-PATH}:. example/example.proto 56 | ``` 57 | 58 | ### Note 59 | 60 | This should always run after protocol buffer compiler has run. The command such as the one below will fail/produce unexpected results. 61 | 62 | ```bash 63 | protoc -I /usr/local/include \ 64 | -I . \ 65 | --go_out=:. \ 66 | --gotag_out=xxx="graphql+\"-\" bson+\"-\"",output_path={OUTPUT-PATH}:. example/example.proto 67 | ``` 68 | -------------------------------------------------------------------------------- /tagger/tagger.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // source: tagger/tagger.proto 3 | 4 | package tagger // import "github.com/amsokol/protoc-gen-gotag/tagger" 5 | 6 | import proto "github.com/golang/protobuf/proto" 7 | import fmt "fmt" 8 | import math "math" 9 | import descriptor "github.com/golang/protobuf/protoc-gen-go/descriptor" 10 | 11 | // Reference imports to suppress errors if they are not otherwise used. 12 | var _ = proto.Marshal 13 | var _ = fmt.Errorf 14 | var _ = math.Inf 15 | 16 | // This is a compile-time assertion to ensure that this generated file 17 | // is compatible with the proto package it is being compiled against. 18 | // A compilation error at this line likely means your copy of the 19 | // proto package needs to be updated. 20 | const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package 21 | 22 | var E_Tags = &proto.ExtensionDesc{ 23 | ExtendedType: (*descriptor.FieldOptions)(nil), 24 | ExtensionType: (*string)(nil), 25 | Field: 847939, 26 | Name: "tagger.tags", 27 | Tag: "bytes,847939,opt,name=tags", 28 | Filename: "tagger/tagger.proto", 29 | } 30 | 31 | var E_OneofTags = &proto.ExtensionDesc{ 32 | ExtendedType: (*descriptor.OneofOptions)(nil), 33 | ExtensionType: (*string)(nil), 34 | Field: 847939, 35 | Name: "tagger.oneof_tags", 36 | Tag: "bytes,847939,opt,name=oneof_tags,json=oneofTags", 37 | Filename: "tagger/tagger.proto", 38 | } 39 | 40 | func init() { 41 | proto.RegisterExtension(E_Tags) 42 | proto.RegisterExtension(E_OneofTags) 43 | } 44 | 45 | func init() { proto.RegisterFile("tagger/tagger.proto", fileDescriptor_tagger_405e48db8be7f212) } 46 | 47 | var fileDescriptor_tagger_405e48db8be7f212 = []byte{ 48 | // 181 bytes of a gzipped FileDescriptorProto 49 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2e, 0x49, 0x4c, 0x4f, 50 | 0x4f, 0x2d, 0xd2, 0x87, 0x50, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0x6c, 0x10, 0x9e, 0x94, 51 | 0x42, 0x7a, 0x7e, 0x7e, 0x7a, 0x4e, 0xaa, 0x3e, 0x58, 0x34, 0xa9, 0x34, 0x4d, 0x3f, 0x25, 0xb5, 52 | 0x38, 0xb9, 0x28, 0xb3, 0xa0, 0x24, 0x1f, 0xaa, 0xd2, 0xca, 0x98, 0x8b, 0xa5, 0x24, 0x31, 0xbd, 53 | 0x58, 0x48, 0x56, 0x0f, 0xa2, 0x54, 0x0f, 0xa6, 0x54, 0xcf, 0x2d, 0x33, 0x35, 0x27, 0xc5, 0xbf, 54 | 0xa0, 0x24, 0x33, 0x3f, 0xaf, 0x58, 0xe2, 0xf0, 0x03, 0x63, 0x05, 0x46, 0x0d, 0xce, 0x20, 0xb0, 55 | 0x62, 0x2b, 0x3b, 0x2e, 0xae, 0xfc, 0xbc, 0xd4, 0xfc, 0xb4, 0x78, 0x1c, 0x5a, 0xfd, 0x41, 0x92, 56 | 0xe8, 0x5a, 0x39, 0xc1, 0x5a, 0x42, 0x12, 0xd3, 0x8b, 0x9d, 0x4c, 0xa2, 0x8c, 0xd2, 0x33, 0x4b, 57 | 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, 0xf5, 0x8b, 0x8b, 0x32, 0xb3, 0x8b, 0x8a, 0xf3, 0x12, 58 | 0x21, 0xae, 0x4c, 0xd6, 0x4d, 0x4f, 0xcd, 0xd3, 0x4d, 0xcf, 0x2f, 0x49, 0x4c, 0x87, 0xfa, 0xc9, 59 | 0x1a, 0x42, 0x25, 0xb1, 0x81, 0xe5, 0x8d, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x7c, 0x4b, 0x5c, 60 | 0x8f, 0xf2, 0x00, 0x00, 0x00, 61 | } 62 | -------------------------------------------------------------------------------- /example/example.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // source: example/example.proto 3 | 4 | package example 5 | 6 | import proto "github.com/golang/protobuf/proto" 7 | import fmt "fmt" 8 | import math "math" 9 | import _ "github.com/amsokol/protoc-gen-gotag/tagger" 10 | 11 | // Reference imports to suppress errors if they are not otherwise used. 12 | var _ = proto.Marshal 13 | var _ = fmt.Errorf 14 | var _ = math.Inf 15 | 16 | // This is a compile-time assertion to ensure that this generated file 17 | // is compatible with the proto package it is being compiled against. 18 | // A compilation error at this line likely means your copy of the 19 | // proto package needs to be updated. 20 | const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package 21 | 22 | type Example struct { 23 | WithNewTags string `protobuf:"bytes,1,opt,name=with_new_tags,json=withNewTags,proto3" json:"with_new_tags,omitempty" graphql:"withNewTags,optional"` 24 | WithNewMultiple string `protobuf:"bytes,2,opt,name=with_new_multiple,json=withNewMultiple,proto3" json:"with_new_multiple,omitempty" graphql:"withNewTags,optional" xml:"multi,omitempty"` 25 | ReplaceDefault string `protobuf:"bytes,3,opt,name=replace_default,json=replaceDefault,proto3" json:"replacePrevious"` 26 | // Types that are valid to be assigned to OneOf: 27 | // *Example_A 28 | // *Example_BJk 29 | OneOf isExample_OneOf `protobuf_oneof:"one_of" graphql:"withNewTags,optional"` 30 | XXX_NoUnkeyedLiteral struct{} `json:"-" graphql:"-" bson:"-"` 31 | XXX_unrecognized []byte `json:"-" graphql:"-" bson:"-"` 32 | XXX_sizecache int32 `json:"-" graphql:"-" bson:"-"` 33 | } 34 | 35 | func (m *Example) Reset() { *m = Example{} } 36 | func (m *Example) String() string { return proto.CompactTextString(m) } 37 | func (*Example) ProtoMessage() {} 38 | func (*Example) Descriptor() ([]byte, []int) { 39 | return fileDescriptor_example_3ca121c20107e13d, []int{0} 40 | } 41 | func (m *Example) XXX_Unmarshal(b []byte) error { 42 | return xxx_messageInfo_Example.Unmarshal(m, b) 43 | } 44 | func (m *Example) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 45 | return xxx_messageInfo_Example.Marshal(b, m, deterministic) 46 | } 47 | func (dst *Example) XXX_Merge(src proto.Message) { 48 | xxx_messageInfo_Example.Merge(dst, src) 49 | } 50 | func (m *Example) XXX_Size() int { 51 | return xxx_messageInfo_Example.Size(m) 52 | } 53 | func (m *Example) XXX_DiscardUnknown() { 54 | xxx_messageInfo_Example.DiscardUnknown(m) 55 | } 56 | 57 | var xxx_messageInfo_Example proto.InternalMessageInfo 58 | 59 | func (m *Example) GetWithNewTags() string { 60 | if m != nil { 61 | return m.WithNewTags 62 | } 63 | return "" 64 | } 65 | 66 | func (m *Example) GetWithNewMultiple() string { 67 | if m != nil { 68 | return m.WithNewMultiple 69 | } 70 | return "" 71 | } 72 | 73 | func (m *Example) GetReplaceDefault() string { 74 | if m != nil { 75 | return m.ReplaceDefault 76 | } 77 | return "" 78 | } 79 | 80 | type isExample_OneOf interface { 81 | isExample_OneOf() 82 | } 83 | 84 | type Example_A struct { 85 | A string `protobuf:"bytes,5,opt,name=a,proto3,oneof" json:"A"` 86 | } 87 | 88 | type Example_BJk struct { 89 | BJk int32 `protobuf:"varint,6,opt,name=b_jk,json=bJk,proto3,oneof" json:"b_Jk"` 90 | } 91 | 92 | func (*Example_A) isExample_OneOf() {} 93 | 94 | func (*Example_BJk) isExample_OneOf() {} 95 | 96 | func (m *Example) GetOneOf() isExample_OneOf { 97 | if m != nil { 98 | return m.OneOf 99 | } 100 | return nil 101 | } 102 | 103 | func (m *Example) GetA() string { 104 | if x, ok := m.GetOneOf().(*Example_A); ok { 105 | return x.A 106 | } 107 | return "" 108 | } 109 | 110 | func (m *Example) GetBJk() int32 { 111 | if x, ok := m.GetOneOf().(*Example_BJk); ok { 112 | return x.BJk 113 | } 114 | return 0 115 | } 116 | 117 | // XXX_OneofFuncs is for the internal use of the proto package. 118 | func (*Example) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { 119 | return _Example_OneofMarshaler, _Example_OneofUnmarshaler, _Example_OneofSizer, []interface{}{ 120 | (*Example_A)(nil), 121 | (*Example_BJk)(nil), 122 | } 123 | } 124 | 125 | func _Example_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { 126 | m := msg.(*Example) 127 | // one_of 128 | switch x := m.OneOf.(type) { 129 | case *Example_A: 130 | b.EncodeVarint(5<<3 | proto.WireBytes) 131 | b.EncodeStringBytes(x.A) 132 | case *Example_BJk: 133 | b.EncodeVarint(6<<3 | proto.WireVarint) 134 | b.EncodeVarint(uint64(x.BJk)) 135 | case nil: 136 | default: 137 | return fmt.Errorf("Example.OneOf has unexpected type %T", x) 138 | } 139 | return nil 140 | } 141 | 142 | func _Example_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { 143 | m := msg.(*Example) 144 | switch tag { 145 | case 5: // one_of.a 146 | if wire != proto.WireBytes { 147 | return true, proto.ErrInternalBadWireType 148 | } 149 | x, err := b.DecodeStringBytes() 150 | m.OneOf = &Example_A{x} 151 | return true, err 152 | case 6: // one_of.b_jk 153 | if wire != proto.WireVarint { 154 | return true, proto.ErrInternalBadWireType 155 | } 156 | x, err := b.DecodeVarint() 157 | m.OneOf = &Example_BJk{int32(x)} 158 | return true, err 159 | default: 160 | return false, nil 161 | } 162 | } 163 | 164 | func _Example_OneofSizer(msg proto.Message) (n int) { 165 | m := msg.(*Example) 166 | // one_of 167 | switch x := m.OneOf.(type) { 168 | case *Example_A: 169 | n += 1 // tag and wire 170 | n += proto.SizeVarint(uint64(len(x.A))) 171 | n += len(x.A) 172 | case *Example_BJk: 173 | n += 1 // tag and wire 174 | n += proto.SizeVarint(uint64(x.BJk)) 175 | case nil: 176 | default: 177 | panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) 178 | } 179 | return n 180 | } 181 | 182 | type SecondMessage struct { 183 | WithNewTags string `protobuf:"bytes,1,opt,name=with_new_tags,json=withNewTags,proto3" json:"with_new_tags,omitempty" graphql:"withNewTags,optional"` 184 | WithNewMultiple string `protobuf:"bytes,2,opt,name=with_new_multiple,json=withNewMultiple,proto3" json:"with_new_multiple,omitempty" graphql:"withNewTags,optional" xml:"multi,omitempty"` 185 | ReplaceDefault string `protobuf:"bytes,3,opt,name=replace_default,json=replaceDefault,proto3" json:"replacePrevious"` 186 | XXX_NoUnkeyedLiteral struct{} `json:"-" graphql:"-" bson:"-"` 187 | XXX_unrecognized []byte `json:"-" graphql:"-" bson:"-"` 188 | XXX_sizecache int32 `json:"-" graphql:"-" bson:"-"` 189 | } 190 | 191 | func (m *SecondMessage) Reset() { *m = SecondMessage{} } 192 | func (m *SecondMessage) String() string { return proto.CompactTextString(m) } 193 | func (*SecondMessage) ProtoMessage() {} 194 | func (*SecondMessage) Descriptor() ([]byte, []int) { 195 | return fileDescriptor_example_3ca121c20107e13d, []int{1} 196 | } 197 | func (m *SecondMessage) XXX_Unmarshal(b []byte) error { 198 | return xxx_messageInfo_SecondMessage.Unmarshal(m, b) 199 | } 200 | func (m *SecondMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 201 | return xxx_messageInfo_SecondMessage.Marshal(b, m, deterministic) 202 | } 203 | func (dst *SecondMessage) XXX_Merge(src proto.Message) { 204 | xxx_messageInfo_SecondMessage.Merge(dst, src) 205 | } 206 | func (m *SecondMessage) XXX_Size() int { 207 | return xxx_messageInfo_SecondMessage.Size(m) 208 | } 209 | func (m *SecondMessage) XXX_DiscardUnknown() { 210 | xxx_messageInfo_SecondMessage.DiscardUnknown(m) 211 | } 212 | 213 | var xxx_messageInfo_SecondMessage proto.InternalMessageInfo 214 | 215 | func (m *SecondMessage) GetWithNewTags() string { 216 | if m != nil { 217 | return m.WithNewTags 218 | } 219 | return "" 220 | } 221 | 222 | func (m *SecondMessage) GetWithNewMultiple() string { 223 | if m != nil { 224 | return m.WithNewMultiple 225 | } 226 | return "" 227 | } 228 | 229 | func (m *SecondMessage) GetReplaceDefault() string { 230 | if m != nil { 231 | return m.ReplaceDefault 232 | } 233 | return "" 234 | } 235 | 236 | func init() { 237 | proto.RegisterType((*Example)(nil), "example.Example") 238 | proto.RegisterType((*SecondMessage)(nil), "example.SecondMessage") 239 | } 240 | 241 | func init() { proto.RegisterFile("example/example.proto", fileDescriptor_example_3ca121c20107e13d) } 242 | 243 | var fileDescriptor_example_3ca121c20107e13d = []byte{ 244 | // 319 bytes of a gzipped FileDescriptorProto 245 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x92, 0xc1, 0x4a, 0x33, 0x31, 246 | 0x10, 0xc7, 0xbf, 0x6d, 0xbf, 0xb6, 0x9a, 0x52, 0xab, 0x11, 0x65, 0x51, 0x94, 0x12, 0x11, 0x7a, 247 | 0xa8, 0xf6, 0xa0, 0x17, 0x7b, 0xb3, 0x54, 0x94, 0x42, 0x45, 0x56, 0xef, 0x4b, 0xb6, 0x9d, 0xa6, 248 | 0xdb, 0x66, 0x37, 0x71, 0x93, 0xba, 0xf5, 0xae, 0x2f, 0xe1, 0xc1, 0xa7, 0xf4, 0x01, 0x24, 0x9b, 249 | 0x20, 0x9e, 0xc4, 0xbb, 0xa7, 0x21, 0x93, 0xdf, 0xff, 0x37, 0x30, 0x0c, 0xda, 0x81, 0x15, 0x4d, 250 | 0x24, 0x87, 0xae, 0xab, 0xa7, 0x32, 0x13, 0x5a, 0xe0, 0x9a, 0x7b, 0xee, 0x6d, 0x6b, 0xca, 0x18, 251 | 0x64, 0x5d, 0x5b, 0xec, 0x2f, 0xf9, 0x28, 0xa1, 0xda, 0x95, 0x05, 0xf0, 0x35, 0x6a, 0xe4, 0xb1, 252 | 0x9e, 0x85, 0x29, 0xe4, 0xa1, 0xa6, 0x4c, 0xf9, 0x5e, 0xcb, 0x6b, 0xaf, 0xf7, 0x8f, 0xde, 0x5e, 253 | 0xde, 0xcb, 0x87, 0x2c, 0xa3, 0x72, 0xf6, 0xc8, 0x7b, 0xc4, 0x20, 0xb7, 0x90, 0x3f, 0x50, 0xa6, 254 | 0x3a, 0x42, 0xea, 0x58, 0xa4, 0x94, 0x93, 0xa0, 0xfe, 0xad, 0x8d, 0x01, 0x6d, 0x7d, 0x89, 0x92, 255 | 0x25, 0xd7, 0xb1, 0xe4, 0xe0, 0x97, 0x0a, 0xd9, 0x85, 0x91, 0x9d, 0xff, 0x2c, 0x6b, 0xad, 0x12, 256 | 0xde, 0x23, 0x45, 0xb0, 0x23, 0x92, 0x58, 0x43, 0x22, 0xf5, 0x33, 0x09, 0x9a, 0x0e, 0x1e, 0x39, 257 | 0x23, 0x1e, 0xa0, 0x66, 0x06, 0x92, 0xd3, 0x31, 0x84, 0x13, 0x98, 0xd2, 0x25, 0xd7, 0x7e, 0xb9, 258 | 0x18, 0xb2, 0x6f, 0x86, 0xec, 0xce, 0x95, 0x48, 0x7b, 0xc4, 0x11, 0x77, 0x19, 0x3c, 0xc5, 0x62, 259 | 0xa9, 0x48, 0xb0, 0xe1, 0x3a, 0x03, 0x1b, 0xc1, 0x07, 0xc8, 0xa3, 0x7e, 0xa5, 0xc8, 0x35, 0x4c, 260 | 0x6e, 0xcd, 0xe6, 0x2e, 0xc9, 0xcd, 0xbf, 0xc0, 0xa3, 0xf8, 0x18, 0xfd, 0x8f, 0xc2, 0xf9, 0xc2, 261 | 0xaf, 0xb6, 0xbc, 0x76, 0xa5, 0xbf, 0x69, 0x88, 0xba, 0x25, 0xa2, 0x70, 0xb8, 0x30, 0x50, 0x39, 262 | 0x1a, 0x2e, 0xfa, 0x27, 0xa8, 0x2a, 0x52, 0x08, 0xc5, 0x14, 0xff, 0x66, 0x5d, 0xe4, 0xb5, 0x84, 263 | 0x1a, 0xf7, 0x30, 0x16, 0xe9, 0x64, 0x04, 0x4a, 0x51, 0xf6, 0x47, 0x97, 0x1f, 0x55, 0x8b, 0x2b, 264 | 0x3c, 0xfb, 0x0c, 0x00, 0x00, 0xff, 0xff, 0x18, 0x14, 0x82, 0x3f, 0xbc, 0x02, 0x00, 0x00, 265 | } 266 | --------------------------------------------------------------------------------