Skip to content

Commit

Permalink
Initial change for v2.
Browse files Browse the repository at this point in the history
As per: #275

The main goals are to have separate modules per each implementation and all reusing same code.
This way we can ensure consistency, and we reduce LOC to minimum, including tests.

## Changes:

* [x] Removed grpc_ prefix from all packages like `grpc_middleware`. User can add them on their own.
* [x] Moved all specific implementations to separate modules. Exception is opentracing, as opentracing itself
is just amazing interface, so.. perfect (:
* [x] Added generic interceptor code that both monitoring, logging and tracing will use under /interceptors
* [x] Reuse generic interceptors in interceptor/{logging,tracing,metrics,tags}. This allows huge simplificaiton of those.
* [x] No context logger. Only ctxtags.Tags responsible for propagating tags in context and proto messages.
* [x] Tags are now map[string]string to discourage context value abuse.
* [x] PayloadUnary works as a standalone interceptor as well.
* [x] Tags will actually will use map tag instead of noop if not created.
* [x] Added scripts for proto generation.
* [x] Let tag.Interceptor to extract request data for all types of requests.

Signed-off-by: Bartlomiej Plotka <[email protected]>
  • Loading branch information
bwplotka committed Mar 4, 2020
1 parent 3ce3d51 commit 7701174
Show file tree
Hide file tree
Showing 145 changed files with 4,550 additions and 5,926 deletions.
5 changes: 4 additions & 1 deletion makefile → Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ vet:
# do not check lostcancel, they are intentional.
go vet -lostcancel=false $(GOFILES_NOVENDOR)

test: vet
test_proto: ./grpctesting/testproto/test.proto
@scripts/genproto.sh

test: test_proto vet
./scripts/test_all.sh

.PHONY: all test
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Go gRPC Middleware
# Go gRPC Middleware V2

[![Travis Build](https://travis-ci.org/grpc-ecosystem/go-grpc-middleware.svg?branch=master)](https://travis-ci.org/grpc-ecosystem/go-grpc-middleware)
[![Go Report Card](https://goreportcard.com/badge/github.com/grpc-ecosystem/go-grpc-middleware)](https://goreportcard.com/report/github.com/grpc-ecosystem/go-grpc-middleware)
Expand Down Expand Up @@ -47,6 +47,8 @@ myServer := grpc.NewServer(
)
```

// TODO(bwplotka) explain changes.

## Interceptors

*Please send a PR to add new interceptors or middleware to this list*
Expand All @@ -55,23 +57,23 @@ myServer := grpc.NewServer(
* [`grpc_auth`](auth) - a customizable (via `AuthFunc`) piece of auth middleware

#### Logging
* [`grpc_ctxtags`](tags/) - a library that adds a `Tag` map to context, with data populated from request body
* [`grpc_zap`](logging/zap/) - integration of [zap](https://github.com/uber-go/zap) logging library into gRPC handlers.
* [`grpc_logrus`](logging/logrus/) - integration of [logrus](https://github.com/sirupsen/logrus) logging library into gRPC handlers.
* [`grpc_kit`](logging/kit/) - integration of [go-kit](https://github.com/go-kit/kit/tree/master/log) logging library into gRPC handlers.
* [`grpc_ctxtags`](interceptors/tags/) - a library that adds a `Tag` map to context, with data populated from request body
* [`grpc_zap`](interceptors/logging/zap/) - integration of [zap](https://github.com/uber-go/zap) logging library into gRPC handlers.
* [`grpc_logrus`](interceptors/logging/logrus/) - integration of [logrus](https://github.com/sirupsen/logrus) logging library into gRPC handlers.
* [`grpc_kit`](interceptors/logging/kit/) - integration of [go-kit](https://github.com/go-kit/kit/tree/master/log) logging library into gRPC handlers.

#### Monitoring
* [`grpc_prometheus`](https://github.com/grpc-ecosystem/go-grpc-prometheus) - Prometheus client-side and server-side monitoring middleware
* [`otgrpc`](https://github.com/grpc-ecosystem/grpc-opentracing/tree/master/go/otgrpc) - [OpenTracing](http://opentracing.io/) client-side and server-side interceptors
* [`grpc_opentracing`](tracing/opentracing) - [OpenTracing](http://opentracing.io/) client-side and server-side interceptors with support for streaming and handler-returned tags
* [`grpc_opentracing`](interceptors/tracing/opentracing) - [OpenTracing](http://opentracing.io/) client-side and server-side interceptors with support for streaming and handler-returned tags

#### Client
* [`grpc_retry`](retry/) - a generic gRPC response code retry mechanism, client-side middleware
* [`grpc_retry`](interceptors/retry/) - a generic gRPC response code retry mechanism, client-side middleware

#### Server
* [`grpc_validator`](validator/) - codegen inbound message validation from `.proto` options
* [`grpc_recovery`](recovery/) - turn panics into gRPC errors
* [`ratelimit`](ratelimit/) - grpc rate limiting by your own limiter
* [`grpc_validator`](interceptors/validator/) - codegen inbound message validation from `.proto` options
* [`grpc_recovery`](interceptors/recovery/) - turn panics into gRPC errors
* [`ratelimit`](interceptors/ratelimit/) - grpc rate limiting by your own limiter


## Status
Expand Down
6 changes: 3 additions & 3 deletions auth/auth.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright 2016 Michal Witkowski. All Rights Reserved.
// See LICENSE for licensing terms.

package grpc_auth
package auth

import (
"context"

"github.com/grpc-ecosystem/go-grpc-middleware"
middleware "github.com/grpc-ecosystem/go-grpc-middleware"
"google.golang.org/grpc"
)

Expand Down Expand Up @@ -61,7 +61,7 @@ func StreamServerInterceptor(authFunc AuthFunc) grpc.StreamServerInterceptor {
if err != nil {
return err
}
wrapped := grpc_middleware.WrapServerStream(stream)
wrapped := middleware.WrapServerStream(stream)
wrapped.WrappedContext = newCtx
return handler(srv, wrapped)
}
Expand Down
7 changes: 3 additions & 4 deletions auth/auth_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
// Copyright 2016 Michal Witkowski. All Rights Reserved.
// See LICENSE for licensing terms.

package grpc_auth_test
package auth_test

import (
"context"
"fmt"
"testing"
"time"

"github.com/grpc-ecosystem/go-grpc-middleware/auth"
"github.com/grpc-ecosystem/go-grpc-middleware/testing"
pb_testproto "github.com/grpc-ecosystem/go-grpc-middleware/testing/testproto"
grpc_testing "github.com/grpc-ecosystem/go-grpc-middleware/grpctesting"
pb_testproto "github.com/grpc-ecosystem/go-grpc-middleware/grpctesting/testproto"
"github.com/grpc-ecosystem/go-grpc-middleware/util/metautils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down
4 changes: 2 additions & 2 deletions auth/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// See LICENSE for licensing terms.

/*
`grpc_auth` a generic server-side auth middleware for gRPC.
`auth` a generic server-side auth middleware for gRPC.
Server Side Auth Middleware
Expand All @@ -17,4 +17,4 @@ It also allows for per-service implementation overrides of `AuthFunc`. See `Serv
Please see examples for simple examples of use.
*/
package grpc_auth
package auth
14 changes: 7 additions & 7 deletions auth/examples_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package grpc_auth_test
package auth_test

import (
"context"

"github.com/grpc-ecosystem/go-grpc-middleware/auth"
"github.com/grpc-ecosystem/go-grpc-middleware/tags"
grpcauth "github.com/grpc-ecosystem/go-grpc-middleware/auth"
grpc_ctxtags "github.com/grpc-ecosystem/go-grpc-middleware/interceptors/tags"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

func parseToken(token string) (struct{}, error) {
func parseToken(string) (struct{}, error) {
return struct{}{}, nil
}

Expand All @@ -21,7 +21,7 @@ func userClaimFromToken(struct{}) string {
// Simple example of server initialization code.
func Example_serverConfig() {
exampleAuthFunc := func(ctx context.Context) (context.Context, error) {
token, err := grpc_auth.AuthFromMD(ctx, "bearer")
token, err := grpcauth.AuthFromMD(ctx, "bearer")
if err != nil {
return nil, err
}
Expand All @@ -35,7 +35,7 @@ func Example_serverConfig() {
}

_ = grpc.NewServer(
grpc.StreamInterceptor(grpc_auth.StreamServerInterceptor(exampleAuthFunc)),
grpc.UnaryInterceptor(grpc_auth.UnaryServerInterceptor(exampleAuthFunc)),
grpc.StreamInterceptor(grpcauth.StreamServerInterceptor(exampleAuthFunc)),
grpc.UnaryInterceptor(grpcauth.UnaryServerInterceptor(exampleAuthFunc)),
)
}
2 changes: 1 addition & 1 deletion auth/metadata.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2016 Michal Witkowski. All Rights Reserved.
// See LICENSE for licensing terms.

package grpc_auth
package auth

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion auth/metadata_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2016 Michal Witkowski. All Rights Reserved.
// See LICENSE for licensing terms.

package grpc_auth
package auth

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// gRPC Server Interceptor chaining middleware.

package grpc_middleware
package middleware

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion chain_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2016 Michal Witkowski. All Rights Reserved.
// See LICENSE for licensing terms.

package grpc_middleware
package middleware

import (
"context"
Expand Down
4 changes: 2 additions & 2 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// See LICENSE for licensing terms.

/*
`grpc_middleware` is a collection of gRPC middleware packages: interceptors, helpers and tools.
`middleware` is a collection of gRPC middleware packages: interceptors, helpers and tools.
Middleware
Expand Down Expand Up @@ -66,4 +66,4 @@ needed. For example:
return handler(srv, stream)
}
*/
package grpc_middleware
package middleware
10 changes: 1 addition & 9 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
module github.com/grpc-ecosystem/go-grpc-middleware

require (
github.com/go-kit/kit v0.9.0
github.com/go-logfmt/logfmt v0.4.0 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/gogo/protobuf v1.2.1
github.com/golang/protobuf v1.3.2
github.com/opentracing/opentracing-go v1.1.0
github.com/pkg/errors v0.8.1 // indirect
github.com/sirupsen/logrus v1.4.2
github.com/stretchr/testify v1.4.0
go.uber.org/atomic v1.4.0 // indirect
go.uber.org/multierr v1.1.0 // indirect
go.uber.org/zap v1.10.0
golang.org/x/net v0.0.0-20190311183353-d8887717615a
golang.org/x/net v0.0.0-20190620200207-3b0461eec859
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 // indirect
google.golang.org/grpc v1.19.0
Expand Down
34 changes: 3 additions & 31 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,79 +1,51 @@
cloud.google.com/go v0.26.0 h1:e0WKqKTd5BnrG8aKH3J3h+QvEIQtSUcf2n5UZ5ZgLtQ=
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-kit/kit v0.9.0 h1:wDJmvq38kDhkVxi50ni9ykkdUr1PKgqKOoi01fa0Mdk=
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.4.0 h1:MP4Eh7ZCb31lleYCFuwm0oe4/YGak+5l1vA2NOE80nA=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 h1:T+h1c/A9Gawja4Y9mFVWj2vyii2bbUNDw3kt9VxK2EY=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/zap v1.10.0 h1:ORx85nbTijNz8ljznvCMR1ZBIPKFn3jQrag10X2AsuM=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be h1:vEDujvNQGv4jgYKudGeI/+DAX4Jffq6hpD55MmoEvKs=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
google.golang.org/appengine v1.1.0 h1:igQkv0AAhEIvTEpD5LIpAfav2eeVO9HBTjvKHVJPRSs=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
syntax = "proto3";

// This file is used for testing discovery of log fields from requests using reflection and gogo proto more tags.
// This file is used for grpctesting discovery of log fields from requests using reflection and gogo proto more tags.
package mwitkow.testproto;

import "github.com/gogo/protobuf/gogoproto/gogo.proto";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2016 Michal Witkowski. All Rights Reserved.
// See LICENSE for licensing terms.

package grpc_testing
package grpctesting

import (
"context"
Expand All @@ -11,7 +11,7 @@ import (
"runtime"
"time"

pb_testproto "github.com/grpc-ecosystem/go-grpc-middleware/testing/testproto"
pb_testproto "github.com/grpc-ecosystem/go-grpc-middleware/grpctesting/testproto"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"google.golang.org/grpc"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package grpc_testing
package grpctesting

import (
"io"
Expand Down
14 changes: 7 additions & 7 deletions testing/pingservice.go → grpctesting/pingservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
Package `grpc_testing` provides helper functions for testing validators in this package.
*/

package grpc_testing
package grpctesting

import (
"context"
"io"
"testing"

pb_testproto "github.com/grpc-ecosystem/go-grpc-middleware/testing/testproto"
pb_testproto "github.com/grpc-ecosystem/go-grpc-middleware/grpctesting/testproto"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
Expand All @@ -28,16 +28,16 @@ type TestPingService struct {
T *testing.T
}

func (s *TestPingService) PingEmpty(ctx context.Context, _ *pb_testproto.Empty) (*pb_testproto.PingResponse, error) {
return &pb_testproto.PingResponse{Value: DefaultResponseValue, Counter: 42}, nil
func (s *TestPingService) PingEmpty(_ context.Context, _ *pb_testproto.Empty) (*pb_testproto.PingResponse, error) {
return &pb_testproto.PingResponse{Value: DefaultResponseValue, Counter: 0}, nil
}

func (s *TestPingService) Ping(ctx context.Context, ping *pb_testproto.PingRequest) (*pb_testproto.PingResponse, error) {
func (s *TestPingService) Ping(_ context.Context, ping *pb_testproto.PingRequest) (*pb_testproto.PingResponse, error) {
// Send user trailers and headers.
return &pb_testproto.PingResponse{Value: ping.Value, Counter: 42}, nil
return &pb_testproto.PingResponse{Value: ping.Value, Counter: 0}, nil
}

func (s *TestPingService) PingError(ctx context.Context, ping *pb_testproto.PingRequest) (*pb_testproto.Empty, error) {
func (s *TestPingService) PingError(_ context.Context, ping *pb_testproto.PingRequest) (*pb_testproto.Empty, error) {
code := codes.Code(ping.ErrorCodeReturned)
return nil, status.Errorf(code, "Userspace error.")
}
Expand Down
10 changes: 10 additions & 0 deletions grpctesting/testproto/test.manual_extractfields.pb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Manual code for logging field extraction tests.

package grpc_middleware_testproto

const TestServiceFullName = "grpc_middleware.testproto.TestService"

// This is implementing ctxtags.requestFieldsExtractor
func (m *PingRequest) ExtractRequestFields(appendToMap map[string]string) {
appendToMap["value"] = m.Value
}
Loading

0 comments on commit 7701174

Please sign in to comment.