diff --git a/.circleci/config.yml b/.circleci/config.yml index a2ad7f9c4b7..2707fd7786e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,22 +2,20 @@ version: 2 jobs: build: docker: - - image: "golang:latest" + - image: "jfbrandhorst/grpc-gateway-build-env" working_directory: /go/src/github.com/grpc-ecosystem/grpc-gateway steps: - checkout - - run: curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh - run: dep ensure --vendor-only - run: go build ./... test: docker: - - image: "golang:latest" + - image: "jfbrandhorst/grpc-gateway-build-env" working_directory: /go/src/github.com/grpc-ecosystem/grpc-gateway environment: GLOG_logtostderr: "1" steps: - checkout - - run: curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh - run: dep ensure --vendor-only - run: go test -race -coverprofile=coverage.txt ./... - run: bash <(curl -s https://codecov.io/bash) @@ -27,6 +25,7 @@ jobs: working_directory: /go/src/github.com/grpc-ecosystem/grpc-gateway steps: - checkout + - run: dep ensure --vendor-only - run: > . $HOME/.nvm/nvm.sh && cd examples/browser && @@ -44,13 +43,12 @@ jobs: - run: git diff --exit-code lint: docker: - - image: "golang:latest" + - image: "jfbrandhorst/grpc-gateway-build-env" working_directory: /go/src/github.com/grpc-ecosystem/grpc-gateway steps: - checkout - - run: curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh - run: dep ensure --vendor-only - - run: go get github.com/golang/lint/golint + - run: go get golang.org/x/lint/golint - run: make lint bazel_build: docker: @@ -58,32 +56,14 @@ jobs: working_directory: /go/src/github.com/grpc-ecosystem/grpc-gateway steps: - checkout - - run: > - bazel - --batch - --output_base=$HOME/.cache/_grpc_gateway_bazel - --host_jvm_args=-Xmx500m - --host_jvm_args=-Xms500m - build - --local_resources=400,1,1.0 - //... + - run: bazel --batch --output_base=$HOME/.cache/_grpc_gateway_bazel --host_jvm_args=-Xmx500m --host_jvm_args=-Xms500m build --local_resources=400,1,1.0 //... bazel_test: docker: - image: "l.gcr.io/google/bazel:latest" working_directory: /go/src/github.com/grpc-ecosystem/grpc-gateway steps: - checkout - - run: > - bazel - --batch - --output_base=$HOME/.cache/_grpc_gateway_bazel - --host_jvm_args=-Xmx500m - --host_jvm_args=-Xms500m - test - --local_resources=400,1,1.0 - --test_output=errors - --features=race - //... + - run: bazel --batch --output_base=$HOME/.cache/_grpc_gateway_bazel --host_jvm_args=-Xmx500m --host_jvm_args=-Xms500m test --local_resources=400,1,1.0 --test_output=errors --features=race //... workflows: version: 2 all: diff --git a/Makefile b/Makefile index f2de987b047..5cd992cd635 100644 --- a/Makefile +++ b/Makefile @@ -160,26 +160,22 @@ $(ECHO_EXAMPLE_SRCS): $(ECHO_EXAMPLE_SPEC) $(SWAGGER_CODEGEN) generate -i $(ECHO_EXAMPLE_SPEC) \ -l go -o examples/clients/echo --additional-properties packageName=echo @rm -f $(EXAMPLE_CLIENT_DIR)/echo/README.md \ - $(EXAMPLE_CLIENT_DIR)/echo/git_push.sh \ - $(EXAMPLE_CLIENT_DIR)/echo/.travis.yml + $(EXAMPLE_CLIENT_DIR)/echo/git_push.sh $(ABE_EXAMPLE_SRCS): $(ABE_EXAMPLE_SPEC) $(SWAGGER_CODEGEN) generate -i $(ABE_EXAMPLE_SPEC) \ -l go -o examples/clients/abe --additional-properties packageName=abe @rm -f $(EXAMPLE_CLIENT_DIR)/abe/README.md \ - $(EXAMPLE_CLIENT_DIR)/abe/git_push.sh \ - $(EXAMPLE_CLIENT_DIR)/abe/.travis.yml + $(EXAMPLE_CLIENT_DIR)/abe/git_push.sh $(UNANNOTATED_ECHO_EXAMPLE_SRCS): $(UNANNOTATED_ECHO_EXAMPLE_SPEC) $(SWAGGER_CODEGEN) generate -i $(UNANNOTATED_ECHO_EXAMPLE_SPEC) \ -l go -o examples/clients/unannotatedecho --additional-properties packageName=unannotatedecho @rm -f $(EXAMPLE_CLIENT_DIR)/unannotatedecho/README.md \ - $(EXAMPLE_CLIENT_DIR)/unannotatedecho/git_push.sh \ - $(EXAMPLE_CLIENT_DIR)/unannotatedecho/.travis.yml + $(EXAMPLE_CLIENT_DIR)/unannotatedecho/git_push.sh $(RESPONSE_BODY_EXAMPLE_SRCS): $(RESPONSE_BODY_EXAMPLE_SPEC) $(SWAGGER_CODEGEN) generate -i $(RESPONSE_BODY_EXAMPLE_SPEC) \ -l go -o examples/clients/responsebody --additional-properties packageName=responsebody @rm -f $(EXAMPLE_CLIENT_DIR)/responsebody/README.md \ - $(EXAMPLE_CLIENT_DIR)/responsebody/git_push.sh \ - $(EXAMPLE_CLIENT_DIR)/responsebody/.travis.yml + $(EXAMPLE_CLIENT_DIR)/responsebody/git_push.sh examples: $(EXAMPLE_DEPSRCS) $(EXAMPLE_SVCSRCS) $(EXAMPLE_GWSRCS) $(EXAMPLE_SWAGGERSRCS) $(EXAMPLE_CLIENT_SRCS) test: examples diff --git a/README.md b/README.md index 445368e7118..e10f1b660a1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # grpc-gateway -[![Build Status](https://travis-ci.org/grpc-ecosystem/grpc-gateway.svg?branch=master)](https://travis-ci.org/grpc-ecosystem/grpc-gateway) +[![CircleCI](https://circleci.com/gh/grpc-ecosystem/grpc-gateway.svg?style=svg)](https://circleci.com/gh/grpc-ecosystem/grpc-gateway) grpc-gateway is a plugin of [protoc](http://github.com/google/protobuf). It reads [gRPC](http://github.com/grpc/grpc-common) service definition, @@ -43,12 +43,12 @@ go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger go get -u github.com/golang/protobuf/protoc-gen-go ``` - + ## Usage Make sure that your `$GOPATH/bin` is in your `$PATH`. 1. Define your service in gRPC - + your_service.proto: ```protobuf syntax = "proto3"; @@ -56,13 +56,13 @@ Make sure that your `$GOPATH/bin` is in your `$PATH`. message StringMessage { string value = 1; } - + service YourService { rpc Echo(StringMessage) returns (StringMessage) {} } ``` 2. Add a [`google.api.http`](https://github.com/googleapis/googleapis/blob/master/google/api/http.proto#L46) to your .proto file - + your_service.proto: ```diff syntax = "proto3"; @@ -73,7 +73,7 @@ Make sure that your `$GOPATH/bin` is in your `$PATH`. message StringMessage { string value = 1; } - + service YourService { - rpc Echo(StringMessage) returns (StringMessage) {} + rpc Echo(StringMessage) returns (StringMessage) { @@ -88,7 +88,7 @@ Make sure that your `$GOPATH/bin` is in your `$PATH`. If you do not want to modify the proto file for use with grpc-gateway you can alternatively use an external [gRPC Service Configuration](https://cloud.google.com/endpoints/docs/grpc/grpc-service-config) file. [Check our documentation](https://grpc-ecosystem.github.io/grpc-gateway/docs/grpcapiconfiguration.html) for more information. 3. Generate gRPC stub - + ```sh protoc -I/usr/local/include -I. \ -I$GOPATH/src \ @@ -96,11 +96,11 @@ Make sure that your `$GOPATH/bin` is in your `$PATH`. --go_out=plugins=grpc:. \ path/to/your_service.proto ``` - + It will generate a stub file `path/to/your_service.pb.go`. 4. Implement your service in gRPC as usual 1. (Optional) Generate gRPC stub in the language you want. - + e.g. ```sh protoc -I/usr/local/include -I. \ @@ -108,7 +108,7 @@ Make sure that your `$GOPATH/bin` is in your `$PATH`. -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \ --ruby_out=. \ path/to/your/service_proto - + protoc -I/usr/local/include -I. \ -I$GOPATH/src \ -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \ @@ -118,9 +118,9 @@ Make sure that your `$GOPATH/bin` is in your `$PATH`. ``` 2. Add the googleapis-common-protos gem (or your language equivalent) as a dependency to your project. 3. Implement your service - + 5. Generate reverse-proxy - + ```sh protoc -I/usr/local/include -I. \ -I$GOPATH/src \ @@ -128,13 +128,13 @@ Make sure that your `$GOPATH/bin` is in your `$PATH`. --grpc-gateway_out=logtostderr=true:. \ path/to/your_service.proto ``` - + It will generate a reverse proxy `path/to/your_service.pb.gw.go`. Note: After generating the code for each of the stubs, in order to build the code, you will want to run ```go get .``` from the directory containing the stubs. 6. Write an entrypoint - + Now you need to write an entrypoint of the proxy server. ```go package main @@ -142,38 +142,38 @@ Make sure that your `$GOPATH/bin` is in your `$PATH`. import ( "flag" "net/http" - + "github.com/golang/glog" "golang.org/x/net/context" "github.com/grpc-ecosystem/grpc-gateway/runtime" "google.golang.org/grpc" - + gw "path/to/your_service_package" ) - + var ( echoEndpoint = flag.String("echo_endpoint", "localhost:9090", "endpoint of YourService") ) - + func run() error { ctx := context.Background() ctx, cancel := context.WithCancel(ctx) defer cancel() - + mux := runtime.NewServeMux() opts := []grpc.DialOption{grpc.WithInsecure()} err := gw.RegisterYourServiceHandlerFromEndpoint(ctx, mux, *echoEndpoint, opts) if err != nil { return err } - + return http.ListenAndServe(":8080", mux) } - + func main() { flag.Parse() defer glog.Flush() - + if err := run(); err != nil { glog.Fatal(err) } @@ -240,7 +240,7 @@ But patch is welcome. * [How gRPC error codes map to HTTP status codes in the response](https://github.com/grpc-ecosystem/grpc-gateway/blob/master/runtime/errors.go#L15) * HTTP request source IP is added as `X-Forwarded-For` gRPC request header * HTTP request host is added as `X-Forwarded-Host` gRPC request header -* HTTP `Authorization` header is added as `authorization` gRPC request header +* HTTP `Authorization` header is added as `authorization` gRPC request header * Remaining Permanent HTTP header keys (as specified by the IANA [here](http://www.iana.org/assignments/message-headers/message-headers.xhtml) are prefixed with `grpcgateway-` and added with their values to gRPC request header * HTTP headers that start with 'Grpc-Metadata-' are mapped to gRPC metadata (prefixed with `grpcgateway-`) * While configurable, the default {un,}marshaling uses [jsonpb](https://godoc.org/github.com/golang/protobuf/jsonpb) with `OrigName: true`. diff --git a/docs/index.md b/docs/index.md index 47b6ec026fc..bb36263e758 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,6 +1,6 @@ # grpc-gateway -[![Build Status](https://travis-ci.org/grpc-ecosystem/grpc-gateway.svg?branch=master)](https://travis-ci.org/grpc-ecosystem/grpc-gateway) +[![CircleCI](https://circleci.com/gh/johanbrandhorst/grpc-gateway.svg?style=svg)](https://circleci.com/gh/johanbrandhorst/grpc-gateway) grpc-gateway is a plugin of [protoc](http://github.com/google/protobuf). It reads [gRPC](http://github.com/grpc/grpc-common) service definition,