From e7355eaeb587a3bfe2fb92e7b6628784cb370a91 Mon Sep 17 00:00:00 2001 From: Asim Date: Sat, 9 May 2015 00:42:07 +0100 Subject: [PATCH] update example to use proto3 --- examples/service_client.go | 5 ++--- template/handler/example.go | 3 +-- template/proto/example/example.pb.go | 26 ++++---------------------- template/proto/example/example.proto | 6 +++--- 4 files changed, 10 insertions(+), 30 deletions(-) diff --git a/examples/service_client.go b/examples/service_client.go index 967a413f..a31c5e33 100644 --- a/examples/service_client.go +++ b/examples/service_client.go @@ -3,7 +3,6 @@ package main import ( "fmt" - "github.com/golang/protobuf/proto" "github.com/myodc/go-micro/client" example "github.com/myodc/go-micro/template/proto/example" ) @@ -11,7 +10,7 @@ import ( func main() { // Create new request to service go.micro.service.go-template, method Example.Call req := client.NewRequest("go.micro.service.template", "Example.Call", &example.Request{ - Name: proto.String("John"), + Name: "John", }) // Set arbitrary headers @@ -26,5 +25,5 @@ func main() { return } - fmt.Println(rsp.GetMsg()) + fmt.Println(rsp.Msg) } diff --git a/template/handler/example.go b/template/handler/example.go index e1884788..f55e3f1b 100644 --- a/template/handler/example.go +++ b/template/handler/example.go @@ -2,7 +2,6 @@ package handler import ( "code.google.com/p/go.net/context" - "github.com/golang/protobuf/proto" log "github.com/golang/glog" "github.com/myodc/go-micro/server" @@ -14,7 +13,7 @@ type Example struct{} func (e *Example) Call(ctx context.Context, req *example.Request, rsp *example.Response) error { log.Info("Received Example.Call request") - rsp.Msg = proto.String(server.Id + ": Hello " + req.GetName()) + rsp.Msg = server.Id + ": Hello " + req.Name return nil } diff --git a/template/proto/example/example.pb.go b/template/proto/example/example.pb.go index 7cbe6fd6..dfc87d8c 100644 --- a/template/proto/example/example.pb.go +++ b/template/proto/example/example.pb.go @@ -3,7 +3,7 @@ // DO NOT EDIT! /* -Package go_micro_service_template_example is a generated protocol buffer package. +Package example is a generated protocol buffer package. It is generated from these files: myodc/go-micro/template/proto/example/example.proto @@ -12,46 +12,28 @@ It has these top-level messages: Request Response */ -package go_micro_service_template_example +package example 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 Request struct { - Name *string `protobuf:"bytes,1,req,name=name" json:"name,omitempty"` - XXX_unrecognized []byte `json:"-"` + Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` } func (m *Request) Reset() { *m = Request{} } func (m *Request) String() string { return proto.CompactTextString(m) } func (*Request) ProtoMessage() {} -func (m *Request) GetName() string { - if m != nil && m.Name != nil { - return *m.Name - } - return "" -} - type Response struct { - Msg *string `protobuf:"bytes,1,req,name=msg" json:"msg,omitempty"` - XXX_unrecognized []byte `json:"-"` + Msg string `protobuf:"bytes,1,opt,name=msg" json:"msg,omitempty"` } func (m *Response) Reset() { *m = Response{} } func (m *Response) String() string { return proto.CompactTextString(m) } func (*Response) ProtoMessage() {} -func (m *Response) GetMsg() string { - if m != nil && m.Msg != nil { - return *m.Msg - } - return "" -} - func init() { } diff --git a/template/proto/example/example.proto b/template/proto/example/example.proto index 7e76068f..c8de6e28 100644 --- a/template/proto/example/example.proto +++ b/template/proto/example/example.proto @@ -1,9 +1,9 @@ -package go.micro.service.template.example; +syntax = "proto3"; message Request { - required string name = 1; + optional string name = 1; } message Response { - required string msg = 1; + optional string msg = 1; }