Skip to content

Commit

Permalink
Feature/patch (#2)
Browse files Browse the repository at this point in the history
* Add explicit dependency versions (grpc-ecosystem#696)

Version constraints are copied from existing Bazel rules. In the
future, these version upgrades must be performed atomically.

* Add OpenTracing support to docs (grpc-ecosystem#705)

* protoc-gen-swagger: support all well-known wrapper types

There were a few well-known wrapper types missing from
the wkSchemas map. In specific UInt32Value, UInt64Value
and BytesValue. This change handles them (and maps them to
the same swagger types as the non-wrapped values)

This also fixes the mapping of Int64Value. The Int64Value handling
maps the value to a swagger integer. The documentation for
Int64Value indicates that it should be mapped to a JSON
string (also the mapping for normal int64 in protoc-gen-swagger
maps it to a string, so this was inconsistent.)

* Add test case and proposed fix for path component with trailing colon (and string) (grpc-ecosystem#708)

* If a pattern has no verb, match with a verb arg appended to last component

Parsing out a "verb" from the input path is a convenience for
parsing. Whether the colon and string are _actually_ a verb depends on
the matching HTTP rule. This change gives a verb-less pattern a chance
to match a path by assuming the colon+string suffix are a part of the
final component.

Fixes grpc-ecosystem#224

Signed-off-by: James Hamlin <james@goforward.com>

* Fix up examples

* Make support paths option

Make protoc-gen-grpc-gateway support paths option such like golang/protobuf#515.
  • Loading branch information
razamiDev authored and dmacthedestroyer committed Aug 2, 2018
1 parent a7ddcec commit e78c7c5
Show file tree
Hide file tree
Showing 20 changed files with 605 additions and 91 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ bazel-genfiles
bazel-grpc-gateway
bazel-out
bazel-testlogs

# Go vendor directory
vendor
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ before_install:
- test "${USE_BAZEL}" = true || go get github.com/dghubble/sling
- test "${USE_BAZEL}" = true || go get github.com/go-resty/resty
- test "${USE_BAZEL}" = true || go get github.com/golang/protobuf/proto
- test "${USE_BAZEL}" = true || curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
install:
# Make sure externally referenced packages are go-gettable.
- test "${USE_BAZEL}" = true ||
Expand Down
129 changes: 129 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
required = [
"github.com/golang/protobuf/protoc-gen-go",
]

[prune]
go-tests = true
unused-packages = true

# Constrained versions that are defined in WORKSPACE are at the top

[[constraint]]
# Also defined in WORKSPACE
revision = "0ca9ea5df5451ffdf184b4428c902747c2c11cd7"
name = "github.com/ghodss/yaml"

[[constraint]]
# Also defined in WORKSPACE
revision = "f8815663de1e64d57cdd4ee9e2b2fa96977a030e"
name = "github.com/go-resty/resty"

[[constraint]]
# Also defined in WORKSPACE
revision = "6724a57986aff9bff1a1770e9347036def7c89f6"
name = "github.com/rogpeppe/fastuuid"

[[override]]
# Also defined in WORKSPACE
revision = "eb3733d160e74a9c7e442f435eb3bea458e1d19f"
name = "gopkg.in/yaml.v2"

# These versions are constrained transitively by bazelbuild/rules_go

[[constraint]]
# Also defined in bazelbuild/rules_go
# https://github.com/bazelbuild/rules_go/blob/436452edc29a2f1e0edc22d180fbb57c27e6d0af/go/private/repositories.bzl#L75
revision = "b4deda0973fb4c70b50d226b1af49f3da59f5265"
name = "github.com/golang/protobuf"

[[constraint]]
# Also defined in bazelbuild/rules_go
# https://github.com/bazelbuild/rules_go/blob/436452edc29a2f1e0edc22d180fbb57c27e6d0af/go/private/repositories.bzl#L110
revision = "640f4622ab692b87c2f3a94265e6f579fe38263d"
name = "golang.org/x/net"

[[constraint]]
# Also defined in bazelbuild/rules_go
# https://github.com/bazelbuild/rules_go/blob/436452edc29a2f1e0edc22d180fbb57c27e6d0af/go/private/repositories.bzl#L123
revision = "d11072e7ca9811b1100b80ca0269ac831f06d024"
name = "google.golang.org/grpc"

[[constraint]]
# Also defined in bazelbuild/rules_go
# https://github.com/bazelbuild/rules_go/blob/436452edc29a2f1e0edc22d180fbb57c27e6d0af/go/private/repositories.bzl#L131
revision = "86e600f69ee4704c6efbf6a2a40a5c10700e76c2"
name = "google.golang.org/genproto"

[[constraint]]
# Also defined in bazelbuild/rules_go
# https://github.com/bazelbuild/rules_go/blob/436452edc29a2f1e0edc22d180fbb57c27e6d0af/go/private/repositories.bzl#L138
revision = "23def4e6c14b4da8ac2ed8007337bc5eb5007998"
name = "github.com/golang/glog"

[[override]]
# Also defined in bazelbuild/rules_go
# https://github.com/bazelbuild/rules_go/blob/436452edc29a2f1e0edc22d180fbb57c27e6d0af/go/private/repositories.bzl#L117
revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0"
name = "golang.org/x/text"
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ generate: $(RUNTIME_GO)
.SUFFIXES: .go .proto

$(GO_PLUGIN):
go get $(GO_PLUGIN_PKG)
dep ensure -vendor-only
go install ./vendor/$(GO_PLUGIN_PKG)
go build -o $@ $(GO_PLUGIN_PKG)

$(RUNTIME_GO): $(RUNTIME_PROTO) $(GO_PLUGIN)
Expand Down
4 changes: 2 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ workspace(name = "grpc_ecosystem_grpc_gateway")

http_archive(
name = "io_bazel_rules_go",
url = "https://github.com/bazelbuild/rules_go/releases/download/0.10.3/rules_go-0.10.3.tar.gz",
sha256 = "feba3278c13cde8d67e341a837f69a029f698d7a27ddbb2a202be7a10b22142a",
url = "https://github.com/bazelbuild/rules_go/releases/download/0.12.1/rules_go-0.12.1.tar.gz",
sha256 = "8b68d0630d63d95dacc0016c3bb4b76154fe34fca93efd65d1c366de3fcb4294",
)

http_archive(
Expand Down
38 changes: 38 additions & 0 deletions docs/_docs/customizingyourgateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,44 @@ Or you might want to mutate the response messages to be returned.
mux := runtime.NewServeMux(runtime.WithForwardResponseOption(myFilter))
```

## OpenTracing Support

If your project uses [OpenTracing](https://github.com/opentracing/opentracing-go) and you'd like spans to propagate through the gateway, you can add some middleware which parses the incoming HTTP headers to create a new span correctly.

```go
import (
...
"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext"
)

var grpcGatewayTag = opentracing.Tag{Key: string(ext.Component), Value: "grpc-gateway"}

func tracingWrapper(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
parentSpanContext, err := opentracing.GlobalTracer().Extract(
opentracing.HTTPHeaders,
opentracing.HTTPHeadersCarrier(r.Header))
if err == nil || err == opentracing.ErrSpanContextNotFound {
serverSpan := opentracing.GlobalTracer().StartSpan(
"ServeHTTP",
// this is magical, it attaches the new span to the parent parentSpanContext, and creates an unparented one if empty.
ext.RPCServerOption(parentSpanContext),
grpcGatewayTag,
)
r = r.WithContext(opentracing.ContextWithSpan(r.Context(), serverSpan))
defer serverSpan.Finish()
}
h.ServeHTTP(w, r)
})
}

// Then just wrap the mux returned by runtime.NewServeMux() like this
if err := http.ListenAndServe(":8080", tracingWrapper(mux)); err != nil {
log.Fatalf("failed to start gateway server on 8080: %v", err)
}
```

## Error handler
http://mycodesmells.com/post/grpc-gateway-error-handler

Expand Down
44 changes: 23 additions & 21 deletions examples/proto/examplepb/a_bit_of_everything.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e78c7c5

Please sign in to comment.