Skip to content

Commit

Permalink
adding support for grpc-gateway Register<svc-name>HandlerServer
Browse files Browse the repository at this point in the history
  • Loading branch information
ankurs committed Apr 29, 2021
1 parent 3928149 commit d8bcb54
Show file tree
Hide file tree
Showing 4 changed files with 558 additions and 29 deletions.
73 changes: 54 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Almost all of these interceptors are reusable and can be used in any other proje
- [func DefaultClientInterceptors(defaultOpts ...interface{}) []grpc.UnaryClientInterceptor](<#func-defaultclientinterceptors>)
- [func DefaultInterceptors() []grpc.UnaryServerInterceptor](<#func-defaultinterceptors>)
- [func DefaultStreamInterceptors() []grpc.StreamServerInterceptor](<#func-defaultstreaminterceptors>)
- [func DoHTTPtoGRPC(ctx context.Context, svr interface{}, handler func(ctx context.Context, req interface{}) (interface{}, error), in interface{}) (interface{}, error)](<#func-dohttptogrpc>)
- [func FilterMethodsFunc(ctx context.Context, fullMethodName string) bool](<#func-filtermethodsfunc>)
- [func GRPCClientInterceptor(options ...grpc_opentracing.Option) grpc.UnaryClientInterceptor](<#func-grpcclientinterceptor>)
- [func HystrixClientInterceptor(defaultOpts ...grpc.CallOption) grpc.UnaryClientInterceptor](<#func-hystrixclientinterceptor>)
Expand All @@ -34,6 +35,7 @@ Almost all of these interceptors are reusable and can be used in any other proje
- [func ServerErrorInterceptor() grpc.UnaryServerInterceptor](<#func-servererrorinterceptor>)
- [func ServerErrorStreamInterceptor() grpc.StreamServerInterceptor](<#func-servererrorstreaminterceptor>)
- [func SetFilterFunc(ctx context.Context, ff FilterFunc)](<#func-setfilterfunc>)
- [func TraceIdInterceptor() grpc.UnaryServerInterceptor](<#func-traceidinterceptor>)
- [type FilterFunc](<#type-filterfunc>)


Expand All @@ -46,147 +48,180 @@ var (
)
```

## func [DebugLoggingInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L107>)
## func [DebugLoggingInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L139>)

```go
func DebugLoggingInterceptor() grpc.UnaryServerInterceptor
```

DebugLoggingInterceptor is the interceptor that logs all request/response from a handler

## func [DefaultClientInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L102>)
## func [DefaultClientInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L134>)

```go
func DefaultClientInterceptor(defaultOpts ...interface{}) grpc.UnaryClientInterceptor
```

DefaultClientInterceptor are the set of default interceptors that should be applied to all client calls

## func [DefaultClientInterceptors](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L67>)
## func [DefaultClientInterceptors](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L99>)

```go
func DefaultClientInterceptors(defaultOpts ...interface{}) []grpc.UnaryClientInterceptor
```

DefaultClientInterceptors are the set of default interceptors that should be applied to all client calls

## func [DefaultInterceptors](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L54>)
## func [DefaultInterceptors](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L85>)

```go
func DefaultInterceptors() []grpc.UnaryServerInterceptor
```

DefaultInterceptors are the set of default interceptors that are applied to all coldbrew methods

## func [DefaultStreamInterceptors](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L91>)
## func [DefaultStreamInterceptors](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L123>)

```go
func DefaultStreamInterceptors() []grpc.StreamServerInterceptor
```

DefaultStreamInterceptors are the set of default interceptors that should be applied to all coldbrew streams

## func [FilterMethodsFunc](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L37>)
## func [DoHTTPtoGRPC](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L71>)

```go
func DoHTTPtoGRPC(ctx context.Context, svr interface{}, handler func(ctx context.Context, req interface{}) (interface{}, error), in interface{}) (interface{}, error)
```

DoHTTPtoGRPC allows calling the interceptors when you use the Register\<svc\-name\>HandlerServer in grpc\-gateway\, see example below for reference

```
func (s *svc) Echo(ctx context.Context, req *proto.EchoRequest) (*proto.EchoResponse, error) {
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return s.echo(ctx, req.(*proto.EchoRequest))
}
r, e := doHTTPtoGRPC(ctx, s, handler, req)
if e != nil {
return nil, e.(error)
}
return r.(*proto.EchoResponse), nil
}
func (s *svc) echo(ctx context.Context, req *proto.EchoRequest) (*proto.EchoResponse, error) {
.... implementation ....
}
```

## func [FilterMethodsFunc](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L38>)

```go
func FilterMethodsFunc(ctx context.Context, fullMethodName string) bool
```

FilterMethodsFunc is the default implementation of Filter function

## func [GRPCClientInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L206>)
## func [GRPCClientInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L238>)

```go
func GRPCClientInterceptor(options ...grpc_opentracing.Option) grpc.UnaryClientInterceptor
```

GRPCClientInterceptor is the interceptor that intercepts all cleint requests and adds tracing info to them

## func [HystrixClientInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L211>)
## func [HystrixClientInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L243>)

```go
func HystrixClientInterceptor(defaultOpts ...grpc.CallOption) grpc.UnaryClientInterceptor
```

HystrixClientInterceptor is the interceptor that intercepts all client requests and adds hystrix info to them

## func [NRHttpTracer](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L282>)
## func [NRHttpTracer](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L314>)

```go
func NRHttpTracer(pattern string, h http.HandlerFunc) (string, http.HandlerFunc)
```

NRHttpTracer adds newrelic tracing to this http function

## func [NewRelicClientInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L195>)
## func [NewRelicClientInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L227>)

```go
func NewRelicClientInterceptor() grpc.UnaryClientInterceptor
```

NewRelicClientInterceptor intercepts all client actions and reports them to newrelic

## func [NewRelicInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L142>)
## func [NewRelicInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L174>)

```go
func NewRelicInterceptor() grpc.UnaryServerInterceptor
```

NewRelicInterceptor intercepts all server actions and reports them to newrelic

## func [OptionsInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L133>)
## func [OptionsInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L165>)

```go
func OptionsInterceptor() grpc.UnaryServerInterceptor
```

## func [PanicRecoveryInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L173>)
## func [PanicRecoveryInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L205>)

```go
func PanicRecoveryInterceptor() grpc.UnaryServerInterceptor
```

## func [ResponseTimeLoggingInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L117>)
## func [ResponseTimeLoggingInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L149>)

```go
func ResponseTimeLoggingInterceptor(ff FilterFunc) grpc.UnaryServerInterceptor
```

ResponseTimeLoggingInterceptor logs response time for each request on server

## func [ResponseTimeLoggingStreamInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L250>)
## func [ResponseTimeLoggingStreamInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L282>)

```go
func ResponseTimeLoggingStreamInterceptor() grpc.StreamServerInterceptor
```

ResponseTimeLoggingStreamInterceptor logs response time for stream RPCs\.

## func [ServerErrorInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L154>)
## func [ServerErrorInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L186>)

```go
func ServerErrorInterceptor() grpc.UnaryServerInterceptor
```

ServerErrorInterceptor intercepts all server actions and reports them to error notifier

## func [ServerErrorStreamInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L262>)
## func [ServerErrorStreamInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L294>)

```go
func ServerErrorStreamInterceptor() grpc.StreamServerInterceptor
```

ServerErrorStreamInterceptor intercepts server errors for stream RPCs and reports them to the error notifier\.

## func [SetFilterFunc](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L47>)
## func [SetFilterFunc](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L48>)

```go
func SetFilterFunc(ctx context.Context, ff FilterFunc)
```

SetFilterFunc sets the default filter function to be used by interceptors

## type [FilterFunc](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L34>)
## func [TraceIdInterceptor](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L336>)

```go
func TraceIdInterceptor() grpc.UnaryServerInterceptor
```

TraceIdInterceptor allows injecting trace id from request objects

## type [FilterFunc](<https://github.com/go-coldbrew/interceptors/blob/main/interceptors.go#L35>)

If it returns false\, the given request will not be traced\.

Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ require (
github.com/go-coldbrew/tracing v0.0.0-20210315144405-14fc34cc65e1
github.com/grpc-ecosystem/go-grpc-middleware v1.2.2
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.4.0
github.com/newrelic/go-agent/v3 v3.9.0
github.com/newrelic/go-agent/v3/integrations/nrgrpc v1.1.0
github.com/princjef/gomarkdoc v0.1.3 // indirect
github.com/prometheus/client_golang v1.9.0 // indirect
google.golang.org/grpc v1.34.0
google.golang.org/grpc v1.37.0
)
Loading

0 comments on commit d8bcb54

Please sign in to comment.