From d27a6796efe5748ff56061640dfa6623e3db2f3e Mon Sep 17 00:00:00 2001 From: thinkerou Date: Sun, 2 Jun 2019 22:28:36 +0800 Subject: [PATCH] test: remove msgpack and protobuf --- binding/binding.go | 9 --- binding/binding_body_test.go | 28 -------- binding/binding_test.go | 111 +----------------------------- binding/msgpack.go | 35 ---------- binding/protobuf.go | 36 ---------- context.go | 5 -- context_test.go | 27 -------- go.mod | 2 - go.sum | 4 -- render/msgpack.go | 35 ---------- render/protobuf.go | 36 ---------- render/render.go | 2 - render/render_test.go | 58 ---------------- testdata/protoexample/test.pb.go | 113 ------------------------------- testdata/protoexample/test.proto | 12 ---- 15 files changed, 3 insertions(+), 510 deletions(-) delete mode 100644 binding/msgpack.go delete mode 100644 binding/protobuf.go delete mode 100644 render/msgpack.go delete mode 100644 render/protobuf.go delete mode 100644 testdata/protoexample/test.pb.go delete mode 100644 testdata/protoexample/test.proto diff --git a/binding/binding.go b/binding/binding.go index 520c5109..77e2254d 100644 --- a/binding/binding.go +++ b/binding/binding.go @@ -15,9 +15,6 @@ const ( MIMEPlain = "text/plain" MIMEPOSTForm = "application/x-www-form-urlencoded" MIMEMultipartPOSTForm = "multipart/form-data" - MIMEPROTOBUF = "application/x-protobuf" - MIMEMSGPACK = "application/x-msgpack" - MIMEMSGPACK2 = "application/msgpack" MIMEYAML = "application/x-yaml" ) @@ -74,8 +71,6 @@ var ( Query = queryBinding{} FormPost = formPostBinding{} FormMultipart = formMultipartBinding{} - ProtoBuf = protobufBinding{} - MsgPack = msgpackBinding{} YAML = yamlBinding{} Uri = uriBinding{} ) @@ -92,10 +87,6 @@ func Default(method, contentType string) Binding { return JSON case MIMEXML, MIMEXML2: return XML - case MIMEPROTOBUF: - return ProtoBuf - case MIMEMSGPACK, MIMEMSGPACK2: - return MsgPack case MIMEYAML: return YAML case MIMEMultipartPOSTForm: diff --git a/binding/binding_body_test.go b/binding/binding_body_test.go index 901d429c..c6df9804 100644 --- a/binding/binding_body_test.go +++ b/binding/binding_body_test.go @@ -1,14 +1,10 @@ package binding import ( - "bytes" "io/ioutil" "testing" - "github.com/gin-gonic/gin/testdata/protoexample" - "github.com/golang/protobuf/proto" "github.com/stretchr/testify/assert" - "github.com/ugorji/go/codec" ) func TestBindingBody(t *testing.T) { @@ -31,11 +27,6 @@ func TestBindingBody(t *testing.T) { FOO `, }, - { - name: "MsgPack binding", - binding: MsgPack, - body: msgPackBody(t), - }, { name: "YAML binding", binding: YAML, @@ -51,22 +42,3 @@ func TestBindingBody(t *testing.T) { } } -func msgPackBody(t *testing.T) string { - test := FooStruct{"FOO"} - h := new(codec.MsgpackHandle) - buf := bytes.NewBuffer(nil) - assert.NoError(t, codec.NewEncoder(buf, h).Encode(test)) - return buf.String() -} - -func TestBindingBodyProto(t *testing.T) { - test := protoexample.Test{ - Label: proto.String("FOO"), - } - data, _ := proto.Marshal(&test) - req := requestWithBody("POST", "/", string(data)) - form := protoexample.Test{} - body, _ := ioutil.ReadAll(req.Body) - assert.NoError(t, ProtoBuf.BindBody(body, &form)) - assert.Equal(t, test, form) -} diff --git a/binding/binding_test.go b/binding/binding_test.go index 6710e42b..4a7da537 100644 --- a/binding/binding_test.go +++ b/binding/binding_test.go @@ -18,10 +18,7 @@ import ( "testing" "time" - "github.com/gin-gonic/gin/testdata/protoexample" - "github.com/golang/protobuf/proto" "github.com/stretchr/testify/assert" - "github.com/ugorji/go/codec" ) type appkey struct { @@ -35,12 +32,12 @@ type QueryTest struct { } type FooStruct struct { - Foo string `msgpack:"foo" json:"foo" form:"foo" xml:"foo" binding:"required"` + Foo string `json:"foo" form:"foo" xml:"foo" binding:"required"` } type FooBarStruct struct { FooStruct - Bar string `msgpack:"bar" json:"bar" form:"bar" xml:"bar" binding:"required"` + Bar string `json:"bar" form:"bar" xml:"bar" binding:"required"` } type FooBarFileStruct struct { @@ -57,7 +54,7 @@ type FooBarFileFailStruct struct { type FooDefaultBarStruct struct { FooStruct - Bar string `msgpack:"bar" json:"bar" form:"bar,default=hello" xml:"bar" binding:"required"` + Bar string `json:"bar" form:"bar,default=hello" xml:"bar" binding:"required"` } type FooStructUseNumber struct { @@ -149,12 +146,6 @@ func TestBindingDefault(t *testing.T) { assert.Equal(t, FormMultipart, Default("POST", MIMEMultipartPOSTForm)) assert.Equal(t, FormMultipart, Default("PUT", MIMEMultipartPOSTForm)) - assert.Equal(t, ProtoBuf, Default("POST", MIMEPROTOBUF)) - assert.Equal(t, ProtoBuf, Default("PUT", MIMEPROTOBUF)) - - assert.Equal(t, MsgPack, Default("POST", MIMEMSGPACK)) - assert.Equal(t, MsgPack, Default("PUT", MIMEMSGPACK2)) - assert.Equal(t, YAML, Default("POST", MIMEYAML)) assert.Equal(t, YAML, Default("PUT", MIMEYAML)) } @@ -583,50 +574,6 @@ func TestBindingFormMultipartForMapFail(t *testing.T) { assert.Error(t, err) } -func TestBindingProtoBuf(t *testing.T) { - test := &protoexample.Test{ - Label: proto.String("yes"), - } - data, _ := proto.Marshal(test) - - testProtoBodyBinding(t, - ProtoBuf, "protobuf", - "/", "/", - string(data), string(data[1:])) -} - -func TestBindingProtoBufFail(t *testing.T) { - test := &protoexample.Test{ - Label: proto.String("yes"), - } - data, _ := proto.Marshal(test) - - testProtoBodyBindingFail(t, - ProtoBuf, "protobuf", - "/", "/", - string(data), string(data[1:])) -} - -func TestBindingMsgPack(t *testing.T) { - test := FooStruct{ - Foo: "bar", - } - - h := new(codec.MsgpackHandle) - assert.NotNil(t, h) - buf := bytes.NewBuffer([]byte{}) - assert.NotNil(t, buf) - err := codec.NewEncoder(buf, h).Encode(test) - assert.NoError(t, err) - - data := buf.Bytes() - - testMsgPackBodyBinding(t, - MsgPack, "msgpack", - "/", "/", - string(data), string(data[1:])) -} - func TestValidationFails(t *testing.T) { var obj FooStruct req := requestWithBody("POST", "/", `{"bar": "foo"}`) @@ -1119,64 +1066,12 @@ func testBodyBindingFail(t *testing.T, b Binding, name, path, badPath, body, bad assert.Error(t, err) } -func testProtoBodyBinding(t *testing.T, b Binding, name, path, badPath, body, badBody string) { - assert.Equal(t, name, b.Name()) - - obj := protoexample.Test{} - req := requestWithBody("POST", path, body) - req.Header.Add("Content-Type", MIMEPROTOBUF) - err := b.Bind(req, &obj) - assert.NoError(t, err) - assert.Equal(t, "yes", *obj.Label) - - obj = protoexample.Test{} - req = requestWithBody("POST", badPath, badBody) - req.Header.Add("Content-Type", MIMEPROTOBUF) - err = ProtoBuf.Bind(req, &obj) - assert.Error(t, err) -} - type hook struct{} func (h hook) Read([]byte) (int, error) { return 0, errors.New("error") } -func testProtoBodyBindingFail(t *testing.T, b Binding, name, path, badPath, body, badBody string) { - assert.Equal(t, name, b.Name()) - - obj := protoexample.Test{} - req := requestWithBody("POST", path, body) - - req.Body = ioutil.NopCloser(&hook{}) - req.Header.Add("Content-Type", MIMEPROTOBUF) - err := b.Bind(req, &obj) - assert.Error(t, err) - - obj = protoexample.Test{} - req = requestWithBody("POST", badPath, badBody) - req.Header.Add("Content-Type", MIMEPROTOBUF) - err = ProtoBuf.Bind(req, &obj) - assert.Error(t, err) -} - -func testMsgPackBodyBinding(t *testing.T, b Binding, name, path, badPath, body, badBody string) { - assert.Equal(t, name, b.Name()) - - obj := FooStruct{} - req := requestWithBody("POST", path, body) - req.Header.Add("Content-Type", MIMEMSGPACK) - err := b.Bind(req, &obj) - assert.NoError(t, err) - assert.Equal(t, "bar", obj.Foo) - - obj = FooStruct{} - req = requestWithBody("POST", badPath, badBody) - req.Header.Add("Content-Type", MIMEMSGPACK) - err = MsgPack.Bind(req, &obj) - assert.Error(t, err) -} - func requestWithBody(method, path, body string) (req *http.Request) { req, _ = http.NewRequest(method, path, bytes.NewBufferString(body)) return diff --git a/binding/msgpack.go b/binding/msgpack.go deleted file mode 100644 index b7f73197..00000000 --- a/binding/msgpack.go +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2017 Manu Martinez-Almeida. All rights reserved. -// Use of this source code is governed by a MIT style -// license that can be found in the LICENSE file. - -package binding - -import ( - "bytes" - "io" - "net/http" - - "github.com/ugorji/go/codec" -) - -type msgpackBinding struct{} - -func (msgpackBinding) Name() string { - return "msgpack" -} - -func (msgpackBinding) Bind(req *http.Request, obj interface{}) error { - return decodeMsgPack(req.Body, obj) -} - -func (msgpackBinding) BindBody(body []byte, obj interface{}) error { - return decodeMsgPack(bytes.NewReader(body), obj) -} - -func decodeMsgPack(r io.Reader, obj interface{}) error { - cdc := new(codec.MsgpackHandle) - if err := codec.NewDecoder(r, cdc).Decode(&obj); err != nil { - return err - } - return validate(obj) -} diff --git a/binding/protobuf.go b/binding/protobuf.go deleted file mode 100644 index f9ece928..00000000 --- a/binding/protobuf.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2014 Manu Martinez-Almeida. All rights reserved. -// Use of this source code is governed by a MIT style -// license that can be found in the LICENSE file. - -package binding - -import ( - "io/ioutil" - "net/http" - - "github.com/golang/protobuf/proto" -) - -type protobufBinding struct{} - -func (protobufBinding) Name() string { - return "protobuf" -} - -func (b protobufBinding) Bind(req *http.Request, obj interface{}) error { - buf, err := ioutil.ReadAll(req.Body) - if err != nil { - return err - } - return b.BindBody(buf, obj) -} - -func (protobufBinding) BindBody(body []byte, obj interface{}) error { - if err := proto.Unmarshal(body, obj.(proto.Message)); err != nil { - return err - } - // Here it's same to return validate(obj), but util now we can't add - // `binding:""` to the struct which automatically generate by gen-proto - return nil - // return validate(obj) -} diff --git a/context.go b/context.go index 71337acd..871792f4 100644 --- a/context.go +++ b/context.go @@ -861,11 +861,6 @@ func (c *Context) YAML(code int, obj interface{}) { c.Render(code, render.YAML{Data: obj}) } -// ProtoBuf serializes the given struct as ProtoBuf into the response body. -func (c *Context) ProtoBuf(code int, obj interface{}) { - c.Render(code, render.ProtoBuf{Data: obj}) -} - // String writes the given string into the response body. func (c *Context) String(code int, format string, values ...interface{}) { c.Render(code, render.String{Format: format, Data: values}) diff --git a/context_test.go b/context_test.go index 89cfb446..1052b826 100644 --- a/context_test.go +++ b/context_test.go @@ -22,11 +22,8 @@ import ( "github.com/gin-contrib/sse" "github.com/gin-gonic/gin/binding" - "github.com/golang/protobuf/proto" "github.com/stretchr/testify/assert" "golang.org/x/net/context" - - testdata "github.com/gin-gonic/gin/testdata/protoexample" ) var _ context.Context = &Context{} @@ -1018,30 +1015,6 @@ func TestContextRenderYAML(t *testing.T) { assert.Equal(t, "application/x-yaml; charset=utf-8", w.Header().Get("Content-Type")) } -// TestContextRenderProtoBuf tests that the response is serialized as ProtoBuf -// and Content-Type is set to application/x-protobuf -// and we just use the example protobuf to check if the response is correct -func TestContextRenderProtoBuf(t *testing.T) { - w := httptest.NewRecorder() - c, _ := CreateTestContext(w) - - reps := []int64{int64(1), int64(2)} - label := "test" - data := &testdata.Test{ - Label: &label, - Reps: reps, - } - - c.ProtoBuf(http.StatusCreated, data) - - protoData, err := proto.Marshal(data) - assert.NoError(t, err) - - assert.Equal(t, http.StatusCreated, w.Code) - assert.Equal(t, string(protoData), w.Body.String()) - assert.Equal(t, "application/x-protobuf", w.Header().Get("Content-Type")) -} - func TestContextHeaders(t *testing.T) { c, _ := CreateTestContext(httptest.NewRecorder()) c.Header("Content-Type", "text/plain") diff --git a/go.mod b/go.mod index 1c5e995c..a55a2850 100644 --- a/go.mod +++ b/go.mod @@ -4,13 +4,11 @@ go 1.12 require ( github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3 - github.com/golang/protobuf v1.3.1 github.com/json-iterator/go v1.1.6 github.com/mattn/go-isatty v0.0.7 github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.1 // indirect github.com/stretchr/testify v1.3.0 - github.com/ugorji/go v1.1.4 golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c gopkg.in/go-playground/assert.v1 v1.2.1 // indirect gopkg.in/go-playground/validator.v8 v8.18.2 diff --git a/go.sum b/go.sum index 58104682..a77d7e59 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,6 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3 h1:t8FVkw33L+wilf2QiWkw0UV77qRpcH/JHPKGpKa2E8g= github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s= -github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg= -github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/json-iterator/go v1.1.6 h1:MrUvLMLTMxbqFJ9kzlvat/rYZqZnW3u4wkLzWTaFwKs= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/mattn/go-isatty v0.0.7 h1:UvyT9uN+3r7yLEYSlJsbQGdsaB/a0DlgWP3pql6iwOc= @@ -17,8 +15,6 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/ugorji/go v1.1.4 h1:j4s+tAvLfL3bZyefP2SEWmhBzmuIlH/eqNuPdFPgngw= -github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c h1:uOCk1iQW6Vc18bnC13MfzScl+wdKBmM9Y9kU7Z83/lw= golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= diff --git a/render/msgpack.go b/render/msgpack.go deleted file mode 100644 index dc681fcf..00000000 --- a/render/msgpack.go +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2017 Manu Martinez-Almeida. All rights reserved. -// Use of this source code is governed by a MIT style -// license that can be found in the LICENSE file. - -package render - -import ( - "net/http" - - "github.com/ugorji/go/codec" -) - -// MsgPack contains the given interface object. -type MsgPack struct { - Data interface{} -} - -var msgpackContentType = []string{"application/msgpack; charset=utf-8"} - -// WriteContentType (MsgPack) writes MsgPack ContentType. -func (r MsgPack) WriteContentType(w http.ResponseWriter) { - writeContentType(w, msgpackContentType) -} - -// Render (MsgPack) encodes the given interface object and writes data with custom ContentType. -func (r MsgPack) Render(w http.ResponseWriter) error { - return WriteMsgPack(w, r.Data) -} - -// WriteMsgPack writes MsgPack ContentType and encodes the given interface object. -func WriteMsgPack(w http.ResponseWriter, obj interface{}) error { - writeContentType(w, msgpackContentType) - var mh codec.MsgpackHandle - return codec.NewEncoder(w, &mh).Encode(obj) -} diff --git a/render/protobuf.go b/render/protobuf.go deleted file mode 100644 index 15aca995..00000000 --- a/render/protobuf.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2018 Gin Core Team. All rights reserved. -// Use of this source code is governed by a MIT style -// license that can be found in the LICENSE file. - -package render - -import ( - "net/http" - - "github.com/golang/protobuf/proto" -) - -// ProtoBuf contains the given interface object. -type ProtoBuf struct { - Data interface{} -} - -var protobufContentType = []string{"application/x-protobuf"} - -// Render (ProtoBuf) marshals the given interface object and writes data with custom ContentType. -func (r ProtoBuf) Render(w http.ResponseWriter) error { - r.WriteContentType(w) - - bytes, err := proto.Marshal(r.Data.(proto.Message)) - if err != nil { - return err - } - - _, err = w.Write(bytes) - return err -} - -// WriteContentType (ProtoBuf) writes ProtoBuf ContentType. -func (r ProtoBuf) WriteContentType(w http.ResponseWriter) { - writeContentType(w, protobufContentType) -} diff --git a/render/render.go b/render/render.go index abfc79fc..5d47a81b 100644 --- a/render/render.go +++ b/render/render.go @@ -27,10 +27,8 @@ var ( _ HTMLRender = HTMLDebug{} _ HTMLRender = HTMLProduction{} _ Render = YAML{} - _ Render = MsgPack{} _ Render = Reader{} _ Render = AsciiJSON{} - _ Render = ProtoBuf{} ) func writeContentType(w http.ResponseWriter, value []string) { diff --git a/render/render_test.go b/render/render_test.go index 9d7eaeef..bff2a17b 100644 --- a/render/render_test.go +++ b/render/render_test.go @@ -5,7 +5,6 @@ package render import ( - "bytes" "encoding/xml" "errors" "html/template" @@ -15,40 +14,12 @@ import ( "strings" "testing" - "github.com/golang/protobuf/proto" "github.com/stretchr/testify/assert" - "github.com/ugorji/go/codec" - - testdata "github.com/gin-gonic/gin/testdata/protoexample" ) // TODO unit tests // test errors -func TestRenderMsgPack(t *testing.T) { - w := httptest.NewRecorder() - data := map[string]interface{}{ - "foo": "bar", - } - - (MsgPack{data}).WriteContentType(w) - assert.Equal(t, "application/msgpack; charset=utf-8", w.Header().Get("Content-Type")) - - err := (MsgPack{data}).Render(w) - - assert.NoError(t, err) - - h := new(codec.MsgpackHandle) - assert.NotNil(t, h) - buf := bytes.NewBuffer([]byte{}) - assert.NotNil(t, buf) - err = codec.NewEncoder(buf, h).Encode(data) - - assert.NoError(t, err) - assert.Equal(t, w.Body.String(), string(buf.Bytes())) - assert.Equal(t, "application/msgpack; charset=utf-8", w.Header().Get("Content-Type")) -} - func TestRenderJSON(t *testing.T) { w := httptest.NewRecorder() data := map[string]interface{}{ @@ -281,35 +252,6 @@ func TestRenderYAMLFail(t *testing.T) { assert.Error(t, err) } -// test Protobuf rendering -func TestRenderProtoBuf(t *testing.T) { - w := httptest.NewRecorder() - reps := []int64{int64(1), int64(2)} - label := "test" - data := &testdata.Test{ - Label: &label, - Reps: reps, - } - - (ProtoBuf{data}).WriteContentType(w) - protoData, err := proto.Marshal(data) - assert.NoError(t, err) - assert.Equal(t, "application/x-protobuf", w.Header().Get("Content-Type")) - - err = (ProtoBuf{data}).Render(w) - - assert.NoError(t, err) - assert.Equal(t, string(protoData), w.Body.String()) - assert.Equal(t, "application/x-protobuf", w.Header().Get("Content-Type")) -} - -func TestRenderProtoBufFail(t *testing.T) { - w := httptest.NewRecorder() - data := &testdata.Test{} - err := (ProtoBuf{data}).Render(w) - assert.Error(t, err) -} - func TestRenderXML(t *testing.T) { w := httptest.NewRecorder() data := xmlmap{ diff --git a/testdata/protoexample/test.pb.go b/testdata/protoexample/test.pb.go deleted file mode 100644 index 21997ca1..00000000 --- a/testdata/protoexample/test.pb.go +++ /dev/null @@ -1,113 +0,0 @@ -// Code generated by protoc-gen-go. -// source: test.proto -// DO NOT EDIT! - -/* -Package protoexample is a generated protocol buffer package. - -It is generated from these files: - test.proto - -It has these top-level messages: - Test -*/ -package protoexample - -import proto "github.com/golang/protobuf/proto" -import math "math" - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = math.Inf - -type FOO int32 - -const ( - FOO_X FOO = 17 -) - -var FOO_name = map[int32]string{ - 17: "X", -} -var FOO_value = map[string]int32{ - "X": 17, -} - -func (x FOO) Enum() *FOO { - p := new(FOO) - *p = x - return p -} -func (x FOO) String() string { - return proto.EnumName(FOO_name, int32(x)) -} -func (x *FOO) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(FOO_value, data, "FOO") - if err != nil { - return err - } - *x = FOO(value) - return nil -} - -type Test struct { - Label *string `protobuf:"bytes,1,req,name=label" json:"label,omitempty"` - Type *int32 `protobuf:"varint,2,opt,name=type,def=77" json:"type,omitempty"` - Reps []int64 `protobuf:"varint,3,rep,name=reps" json:"reps,omitempty"` - Optionalgroup *Test_OptionalGroup `protobuf:"group,4,opt,name=OptionalGroup" json:"optionalgroup,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Test) Reset() { *m = Test{} } -func (m *Test) String() string { return proto.CompactTextString(m) } -func (*Test) ProtoMessage() {} - -const Default_Test_Type int32 = 77 - -func (m *Test) GetLabel() string { - if m != nil && m.Label != nil { - return *m.Label - } - return "" -} - -func (m *Test) GetType() int32 { - if m != nil && m.Type != nil { - return *m.Type - } - return Default_Test_Type -} - -func (m *Test) GetReps() []int64 { - if m != nil { - return m.Reps - } - return nil -} - -func (m *Test) GetOptionalgroup() *Test_OptionalGroup { - if m != nil { - return m.Optionalgroup - } - return nil -} - -type Test_OptionalGroup struct { - RequiredField *string `protobuf:"bytes,5,req" json:"RequiredField,omitempty"` - XXX_unrecognized []byte `json:"-"` -} - -func (m *Test_OptionalGroup) Reset() { *m = Test_OptionalGroup{} } -func (m *Test_OptionalGroup) String() string { return proto.CompactTextString(m) } -func (*Test_OptionalGroup) ProtoMessage() {} - -func (m *Test_OptionalGroup) GetRequiredField() string { - if m != nil && m.RequiredField != nil { - return *m.RequiredField - } - return "" -} - -func init() { - proto.RegisterEnum("protoexample.FOO", FOO_name, FOO_value) -} diff --git a/testdata/protoexample/test.proto b/testdata/protoexample/test.proto deleted file mode 100644 index 3e734287..00000000 --- a/testdata/protoexample/test.proto +++ /dev/null @@ -1,12 +0,0 @@ -package protoexample; - -enum FOO {X=17;}; - -message Test { - required string label = 1; - optional int32 type = 2[default=77]; - repeated int64 reps = 3; - optional group OptionalGroup = 4{ - required string RequiredField = 5; - } -}