diff --git a/README.md b/README.md index fbe4a9e..9eff23d 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,11 @@ Blog post: https://coreos.com/blog/gRPC-protobufs-swagger.html To try it all out do this: ``` -$ go get -u github.com/philips/grpc-gateway-example +$ git clone https://github.com/philips/grpc-gateway-example.git +$ glide install +$ go install ./vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway +$ go install ./vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger +$ go build $ grpc-gateway-example serve $ grpc-gateway-example echo "my first rpc echo" $ curl -X POST -k https://localhost:10000/v1/echo -H "Content-Type: text/plain" -d '{"value": "foo"}' diff --git a/echopb/Makefile b/echopb/Makefile index f5f0a91..b6ed92b 100644 --- a/echopb/Makefile +++ b/echopb/Makefile @@ -1,17 +1,17 @@ all: protoc -I/usr/local/include -I. \ -I${GOPATH}/src \ - -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \ + -I../vendor/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \ --go_out=plugins=grpc:. \ service.proto protoc -I/usr/local/include -I. \ -I${GOPATH}/src \ - -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \ + -I../vendor/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \ --grpc-gateway_out=logtostderr=true:. \ service.proto protoc -I/usr/local/include -I. \ -I${GOPATH}/src \ - -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \ + -I../vendor/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \ --swagger_out=logtostderr=true:. \ service.proto go generate . diff --git a/echopb/service.pb.gw.go b/echopb/service.pb.gw.go index 3c8598e..8d5721b 100644 --- a/echopb/service.pb.gw.go +++ b/echopb/service.pb.gw.go @@ -20,12 +20,10 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/status" ) var _ codes.Code var _ io.Reader -var _ status.Status var _ = runtime.String var _ = utilities.NewDoubleArray @@ -34,7 +32,7 @@ func request_EchoService_Echo_0(ctx context.Context, marshaler runtime.Marshaler var metadata runtime.ServerMetadata if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err) } msg, err := client.Echo(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) @@ -85,19 +83,18 @@ func RegisterEchoServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn }(ctx.Done(), cn.CloseNotify()) } inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) + rctx, err := runtime.AnnotateContext(ctx, req) if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) } resp, md, err := request_EchoService_Echo_0(rctx, inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_EchoService_Echo_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_EchoService_Echo_0(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) diff --git a/glide.lock b/glide.lock new file mode 100644 index 0000000..4c5ff37 --- /dev/null +++ b/glide.lock @@ -0,0 +1,99 @@ +hash: 6a37b85ebfb53ae04a95ee1edbb96b2fd88bdf57e7f4e425f3a80b9138d22c6c +updated: 2017-07-04T11:46:32.441039243+08:00 +imports: +- name: github.com/fsnotify/fsnotify + version: 4da3e2cfbabc9f751898f250b49f2439785783a1 +- name: github.com/golang/protobuf + version: 6a1fa9404c0aebf36c879bc50152edcc953910d2 + subpackages: + - jsonpb + - proto + - protoc-gen-go/descriptor + - ptypes/any + - ptypes/struct +- name: github.com/grpc-ecosystem/grpc-gateway + version: 589b126116b5fc961939b3e156c29e4d9d58222f + subpackages: + - runtime + - runtime/internal + - utilities +- name: github.com/hashicorp/hcl + version: 392dba7d905ed5d04a5794ba89f558b27e2ba1ca + subpackages: + - hcl/ast + - hcl/parser + - hcl/scanner + - hcl/strconv + - hcl/token + - json/parser + - json/scanner + - json/token +- name: github.com/inconshreveable/mousetrap + version: 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75 +- name: github.com/magiconair/properties + version: 51463bfca2576e06c62a8504b5c0f06d61312647 +- name: github.com/mitchellh/mapstructure + version: d0303fe809921458f417bcf828397a65db30a7e4 +- name: github.com/pelletier/go-toml + version: 69d355db5304c0f7f809a2edc054553e7142f016 +- name: github.com/philips/go-bindata-assetfs + version: 3dcc96556217539f50599357fb481ac0dc7439b9 +- name: github.com/spf13/afero + version: 9be650865eab0c12963d8753212f4f9c66cdcf12 + subpackages: + - mem +- name: github.com/spf13/cast + version: acbeb36b902d72a7a4c18e8f3241075e7ab763e4 +- name: github.com/spf13/cobra + version: 8c6fa02d2225de0f9bdcb7ca912556f68d172d8c +- name: github.com/spf13/jwalterweatherman + version: 0efa5202c04663c757d84f90f5219c1250baf94f +- name: github.com/spf13/pflag + version: e57e3eeb33f795204c1ca35f56c44f83227c6e66 +- name: github.com/spf13/viper + version: c1de95864d73a5465492829d7cb2dd422b19ac96 +- name: golang.org/x/net + version: 1f9224279e98554b6a6432d4dd998a739f8b2b7c + subpackages: + - context + - http2 + - http2/hpack + - idna + - internal/timeseries + - lex/httplex + - trace +- name: golang.org/x/sys + version: 94b76065f2d2081d0fef24a6e67c571f51a6408a + subpackages: + - unix +- name: golang.org/x/text + version: 2bf8f2a19ec09c670e931282edfe6567f6be21c9 + subpackages: + - secure/bidirule + - transform + - unicode/bidi + - unicode/norm +- name: google.golang.org/genproto + version: aa2eb687b4d3e17154372564ad8d6bf11c3cf21f + subpackages: + - googleapis/api/annotations + - googleapis/rpc/status +- name: google.golang.org/grpc + version: b15215fb911b24a5d61d57feec4233d610530464 + subpackages: + - codes + - credentials + - grpclb/grpc_lb_v1 + - grpclog + - internal + - keepalive + - metadata + - naming + - peer + - stats + - status + - tap + - transport +- name: gopkg.in/yaml.v2 + version: cd8b52f8269e0feb286dfeef29f8fe4d5b397e0b +testImports: [] diff --git a/glide.yaml b/glide.yaml new file mode 100644 index 0000000..17da8ea --- /dev/null +++ b/glide.yaml @@ -0,0 +1,24 @@ +package: github.com/philips/grpc-gateway-example +import: +- package: github.com/golang/protobuf + subpackages: + - proto +- package: github.com/grpc-ecosystem/grpc-gateway + subpackages: + - runtime + - utilities +- package: github.com/philips/go-bindata-assetfs +- package: github.com/spf13/cobra +- package: github.com/spf13/viper +- package: golang.org/x/net + subpackages: + - context +- package: google.golang.org/genproto + subpackages: + - googleapis/api/annotations +- package: google.golang.org/grpc + subpackages: + - codes + - credentials + - grpclog + - status