From b31be7aee7d6c20a1458dd10011a5a79dca1e071 Mon Sep 17 00:00:00 2001 From: chai2010 Date: Wed, 18 Jul 2018 07:20:03 +0800 Subject: [PATCH] refine code --- examples/hello.pb/hello.pb.go | 2 ++ hello2.go => hello-rest.go | 0 protoc-gen-pbgo/pbgo.go | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) rename hello2.go => hello-rest.go (100%) diff --git a/examples/hello.pb/hello.pb.go b/examples/hello.pb/hello.pb.go index dee1908..dcee77b 100644 --- a/examples/hello.pb/hello.pb.go +++ b/examples/hello.pb/hello.pb.go @@ -9,6 +9,7 @@ import math "math" import _ "github.com/chai2010/pbgo" import "encoding/json" +import "io/ioutil" import "net/rpc" import "net/http" import "regexp" @@ -184,6 +185,7 @@ func init() { // Reference imports to suppress errors if they are not otherwise used. var _ = json.Marshal var _ = http.ListenAndServe +var _ = ioutil.ReadAll var _ = regexp.Match var _ = strings.Split var _ = pbgo.PopulateFieldFromPath diff --git a/hello2.go b/hello-rest.go similarity index 100% rename from hello2.go rename to hello-rest.go diff --git a/protoc-gen-pbgo/pbgo.go b/protoc-gen-pbgo/pbgo.go index fe67428..c7f7469 100644 --- a/protoc-gen-pbgo/pbgo.go +++ b/protoc-gen-pbgo/pbgo.go @@ -275,7 +275,7 @@ func {{.ServiceName}}Handler(svc {{.ServiceName}}Interface) http.Handler { http.Error(w, err.Error(), http.StatusBadRequest) return } - err := pbgo.PopulateFieldFromPath(&protoReq, "{{$rest.RequestBody}}", rBody) + err := pbgo.PopulateFieldFromPath(&protoReq, "{{$rest.RequestBody}}", string(rBody)) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) return