You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
runtime.WithMarshalerOption("application/x-msgpack", m),
21
+
)
22
+
```
21
23
22
24
You can see [the default implementation for JSON](https://github.com/grpc-ecosystem/grpc-gateway/blob/master/runtime/marshal_jsonpb.go) for reference.
23
25
24
26
### Using camelCase for JSON
25
27
26
28
The protocol buffer compiler generates camelCase JSON tags that can be used with jsonpb package. By default jsonpb Marshaller uses `OrigName: true` which uses the exact case used in the proto files. To use camelCase for the JSON representation,
unmarshaler: &jsonpb.Unmarshaler{AllowUnknownFields: false}, // explicit "false", &jsonpb.Unmarshaler{} would have the same effect
120
+
}),
120
121
)
121
122
```
122
123
@@ -126,131 +127,127 @@ You might not like [the default mapping rule](https://pkg.go.dev/github.com/grpc
126
127
1. Write a [`HeaderMatcherFunc`](https://pkg.go.dev/github.com/grpc-ecosystem/grpc-gateway/runtime?tab=doc#HeaderMatcherFunc).
127
128
2. Register the function with [`WithIncomingHeaderMatcher`](https://pkg.go.dev/github.com/grpc-ecosystem/grpc-gateway/runtime?tab=doc#WithIncomingHeaderMatcher)
To keep the [the default mapping rule](https://pkg.go.dev/github.com/grpc-ecosystem/grpc-gateway/runtime?tab=doc#DefaultHeaderMatcher) alongside with your own rules write:
func myFilter(ctx context.Context, w http.ResponseWriter, resp proto.Message) error {
200
+
t, ok := resp.(*externalpb.Tokenizer)
201
+
if ok {
202
+
w.Header().Set("X-My-Tracking-Token", t.Token)
203
+
t.Token = ""
204
+
}
205
+
return nil
207
206
}
208
-
209
-
returnnil
210
-
}
211
-
```
207
+
```
212
208
2. Register the filter with [`WithForwardResponseOption`](https://pkg.go.dev/github.com/grpc-ecosystem/grpc-gateway/runtime?tab=doc#WithForwardResponseOption)
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.
The signature of the handler is much more rigid because we need
@@ -362,34 +359,3 @@ these attributes, a gRPC code of `Unknown` (2) is reported. The default
362
359
handler will also include an HTTP code and status, which is derived
363
360
from the gRPC code (or set to `"500 Internal Server Error"` when
364
361
the source error has no gRPC attributes).
365
-
366
-
## Replace a response forwarder per method
367
-
You might want to keep the behavior of the current marshaler but change only a message forwarding of a certain API method.
368
-
369
-
1. write a custom forwarder which is compatible to [`ForwardResponseMessage`](https://pkg.go.dev/github.com/grpc-ecosystem/grpc-gateway/runtime?tab=doc#ForwardResponseMessage) or [`ForwardResponseStream`](https://pkg.go.dev/github.com/grpc-ecosystem/grpc-gateway/runtime?tab=doc#ForwardResponseStream).
370
-
2. replace the default forwarder of the method with your one.
371
-
372
-
e.g. add `forwarder_overwrite.go` into the go package of the generated code,
Copy file name to clipboardExpand all lines: docs/_docs/examples.md
+23-7Lines changed: 23 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,13 +5,29 @@ category: documentation
5
5
# Examples
6
6
7
7
Examples are available under `examples/internal` directory.
8
-
*`proto/examplepb/echo_service.proto`, `proto/examplepb/a_bit_of_everything.proto`, `proto/examplepb/unannotated_echo_service.proto`: service definition
9
-
*`proto/examplepb/echo_service.pb.go`, `proto/examplepb/a_bit_of_everything.pb.go`, `proto/examplepb/unannotated_echo_service.pb.go`: [generated] stub of the service
10
-
*`proto/examplepb/echo_service.pb.gw.go`, `proto/examplepb/a_bit_of_everything.pb.gw.go`, `proto/examplepb/uannotated_echo_service.pb.gw.go`: [generated] reverse proxy for the service
11
-
*`proto/examplepb/unannotated_echo_service.yaml`: gRPC API Configuration for ```unannotated_echo_service.proto```
12
-
*`server/main.go`: service implementation
13
-
*`main.go`: entrypoint of the generated reverse proxy
To use the same port for custom HTTP handlers (e.g. serving `swagger.json`), gRPC-gateway, and a gRPC server, see [this code example by CoreOS](https://github.com/philips/grpc-gateway-example/blob/master/cmd/serve.go) (and its accompanying [blog post](https://coreos.com/blog/grpc-protobufs-swagger.html))
27
+
To use the same port for custom HTTP handlers (e.g. serving `swagger.json`),
28
+
gRPC-gateway, and a gRPC server, see
29
+
[this code example by CoreOS](https://github.com/philips/grpc-gateway-example/blob/master/cmd/serve.go)
0 commit comments