Skip to content

Commit d3bbb1b

Browse files
domgreenyifanzz
authored andcommitted
vet now passes and run from makefile (grpc-ecosystem#111)
1 parent faf6812 commit d3bbb1b

File tree

17 files changed

+112
-441
lines changed

17 files changed

+112
-441
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ install:
1515
- dep ensure
1616

1717
script:
18-
- ./test_all.sh
18+
- make test
1919

2020
after_success:
2121
- bash <(curl -s https://codecov.io/bash)

auth/DOC.md

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* [Overview](#pkg-overview)
55
* [Imported Packages](#pkg-imports)
66
* [Index](#pkg-index)
7-
* [Examples](#pkg-examples)
87

98
## <a name="pkg-overview">Overview</a>
109
`grpc_auth` a generic server-side auth middleware for gRPC.
@@ -21,42 +20,6 @@ It also allows for per-service implementation overrides of `AuthFunc`. See `Serv
2120

2221
Please see examples for simple examples of use.
2322

24-
#### Example:
25-
26-
<details>
27-
<summary>Click to expand code.</summary>
28-
29-
```go
30-
token, err := grpc_auth.AuthFromMD(ctx, "bearer")
31-
if err != nil {
32-
return nil, err
33-
}
34-
tokenInfo, err := parseToken(token)
35-
if err != nil {
36-
return nil, grpc.Errorf(codes.Unauthenticated, "invalid auth token: %v", err)
37-
}
38-
grpc_ctxtags.Extract(ctx).Set("auth.sub", userClaimFromToken(tokenInfo))
39-
newCtx := context.WithValue(ctx, "tokenInfo", tokenInfo)
40-
return newCtx, nil
41-
```
42-
43-
</details>
44-
45-
#### Example:
46-
47-
<details>
48-
<summary>Click to expand code.</summary>
49-
50-
```go
51-
server := grpc.NewServer(
52-
grpc.StreamInterceptor(grpc_auth.StreamServerInterceptor(Example_authfunc)),
53-
grpc.UnaryInterceptor(grpc_auth.UnaryServerInterceptor(Example_authfunc)),
54-
)
55-
return server
56-
```
57-
58-
</details>
59-
6023
## <a name="pkg-imports">Imported Packages</a>
6124

6225
- [github.com/grpc-ecosystem/go-grpc-middleware](./..)
@@ -72,10 +35,6 @@ return server
7235
* [type AuthFunc](#AuthFunc)
7336
* [type ServiceAuthFuncOverride](#ServiceAuthFuncOverride)
7437

75-
#### <a name="pkg-examples">Examples</a>
76-
* [Package (Authfunc)](#example__authfunc)
77-
* [Package (Serverconfig)](#example__serverconfig)
78-
7938
#### <a name="pkg-files">Package files</a>
8039
[auth.go](./auth.go) [doc.go](./doc.go) [metadata.go](./metadata.go)
8140

auth/examples_test.go

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Copyright 2016 Michal Witkowski. All Rights Reserved.
2-
// See LICENSE for licensing terms.
3-
41
package grpc_auth_test
52

63
import (
@@ -11,7 +8,9 @@ import (
118
"google.golang.org/grpc/codes"
129
)
1310

14-
var cc *grpc.ClientConn
11+
var (
12+
cc *grpc.ClientConn
13+
)
1514

1615
func parseToken(token string) (struct{}, error) {
1716
return struct{}{}, nil
@@ -21,27 +20,24 @@ func userClaimFromToken(struct{}) string {
2120
return "foobar"
2221
}
2322

24-
// Simple example of an `AuthFunc` that extracts, verifies the token and sets it in the handler
25-
// contexts.
26-
func Example_authfunc(ctx context.Context) (context.Context, error) {
27-
token, err := grpc_auth.AuthFromMD(ctx, "bearer")
28-
if err != nil {
29-
return nil, err
30-
}
31-
tokenInfo, err := parseToken(token)
32-
if err != nil {
33-
return nil, grpc.Errorf(codes.Unauthenticated, "invalid auth token: %v", err)
23+
// Simple example of server initialization code.
24+
func Example_ServerConfig() {
25+
exampleAuthFunc := func(ctx context.Context) (context.Context, error) {
26+
token, err := grpc_auth.AuthFromMD(ctx, "bearer")
27+
if err != nil {
28+
return nil, err
29+
}
30+
tokenInfo, err := parseToken(token)
31+
if err != nil {
32+
return nil, grpc.Errorf(codes.Unauthenticated, "invalid auth token: %v", err)
33+
}
34+
grpc_ctxtags.Extract(ctx).Set("auth.sub", userClaimFromToken(tokenInfo))
35+
newCtx := context.WithValue(ctx, "tokenInfo", tokenInfo)
36+
return newCtx, nil
3437
}
35-
grpc_ctxtags.Extract(ctx).Set("auth.sub", userClaimFromToken(tokenInfo))
36-
newCtx := context.WithValue(ctx, "tokenInfo", tokenInfo)
37-
return newCtx, nil
38-
}
3938

40-
// Simple example of server initialization code.
41-
func Example_serverconfig() *grpc.Server {
42-
server := grpc.NewServer(
43-
grpc.StreamInterceptor(grpc_auth.StreamServerInterceptor(Example_authfunc)),
44-
grpc.UnaryInterceptor(grpc_auth.UnaryServerInterceptor(Example_authfunc)),
39+
_ = grpc.NewServer(
40+
grpc.StreamInterceptor(grpc_auth.StreamServerInterceptor(exampleAuthFunc)),
41+
grpc.UnaryInterceptor(grpc_auth.UnaryServerInterceptor(exampleAuthFunc)),
4542
)
46-
return server
4743
}

checkup.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

logging/logrus/DOC.md

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* [Overview](#pkg-overview)
55
* [Imported Packages](#pkg-imports)
66
* [Index](#pkg-index)
7-
* [Examples](#pkg-examples)
87

98
## <a name="pkg-overview">Overview</a>
109
`grpc_logrus` is a gRPC logging middleware backed by Logrus loggers
@@ -27,85 +26,6 @@ Logrus can also be made as a backend for gRPC library internals. For that use `R
2726

2827
Please see examples and tests for examples of use.
2928

30-
#### Example:
31-
32-
<details>
33-
<summary>Click to expand code.</summary>
34-
35-
```go
36-
x := func(ctx context.Context, ping *pb_testproto.PingRequest) (*pb_testproto.PingResponse, error) {
37-
// Add fields the ctxtags of the request which will be added to all extracted loggers.
38-
grpc_ctxtags.Extract(ctx).Set("custom_tags.string", "something").Set("custom_tags.int", 1337)
39-
// Extract a single request-scoped logrus.Logger and log messages.
40-
l := grpc_logrus.Extract(ctx)
41-
l.Info("some ping")
42-
l.Info("another ping")
43-
return &pb_testproto.PingResponse{Value: ping.Value}, nil
44-
}
45-
return x
46-
```
47-
48-
</details>
49-
50-
#### Example:
51-
52-
<details>
53-
<summary>Click to expand code.</summary>
54-
55-
```go
56-
// Logrus entry is used, allowing pre-definition of certain fields by the user.
57-
logrusEntry := logrus.NewEntry(logrusLogger)
58-
// Shared options for the logger, with a custom gRPC code to log level function.
59-
opts := []grpc_logrus.Option{
60-
grpc_logrus.WithLevels(customFunc),
61-
}
62-
// Make sure that log statements internal to gRPC library are logged using the zapLogger as well.
63-
grpc_logrus.ReplaceGrpcLogger(logrusEntry)
64-
// Create a server, make sure we put the grpc_ctxtags context before everything else.
65-
server := grpc.NewServer(
66-
grpc_middleware.WithUnaryServerChain(
67-
grpc_ctxtags.UnaryServerInterceptor(grpc_ctxtags.WithFieldExtractor(grpc_ctxtags.CodeGenRequestFieldExtractor)),
68-
grpc_logrus.UnaryServerInterceptor(logrusEntry, opts...),
69-
),
70-
grpc_middleware.WithStreamServerChain(
71-
grpc_ctxtags.StreamServerInterceptor(grpc_ctxtags.WithFieldExtractor(grpc_ctxtags.CodeGenRequestFieldExtractor)),
72-
grpc_logrus.StreamServerInterceptor(logrusEntry, opts...),
73-
),
74-
)
75-
return server
76-
```
77-
78-
</details>
79-
80-
#### Example:
81-
82-
<details>
83-
<summary>Click to expand code.</summary>
84-
85-
```go
86-
// Logrus entry is used, allowing pre-definition of certain fields by the user.
87-
logrusEntry := logrus.NewEntry(logrusLogger)
88-
// Shared options for the logger, with a custom duration to log field function.
89-
opts := []grpc_logrus.Option{
90-
grpc_logrus.WithDurationField(func(duration time.Duration) (key string, value interface{}) {
91-
return "grpc.time_ns", duration.Nanoseconds()
92-
}),
93-
}
94-
server := grpc.NewServer(
95-
grpc_middleware.WithUnaryServerChain(
96-
grpc_ctxtags.UnaryServerInterceptor(),
97-
grpc_logrus.UnaryServerInterceptor(logrusEntry, opts...),
98-
),
99-
grpc_middleware.WithStreamServerChain(
100-
grpc_ctxtags.StreamServerInterceptor(),
101-
grpc_logrus.StreamServerInterceptor(logrusEntry, opts...),
102-
),
103-
)
104-
return server
105-
```
106-
107-
</details>
108-
10929
## <a name="pkg-imports">Imported Packages</a>
11030

11131
- [github.com/golang/protobuf/jsonpb](https://godoc.org/github.com/golang/protobuf/jsonpb)
@@ -143,11 +63,6 @@ return server
14363
* [func WithDurationField(f DurationToField) Option](#WithDurationField)
14464
* [func WithLevels(f CodeToLevel) Option](#WithLevels)
14565

146-
#### <a name="pkg-examples">Examples</a>
147-
* [Package (HandlerUsageUnaryPing)](#example__handlerUsageUnaryPing)
148-
* [Package (Initialization)](#example__initialization)
149-
* [Package (InitializationWithDurationFieldOverride)](#example__initializationWithDurationFieldOverride)
150-
15166
#### <a name="pkg-files">Package files</a>
15267
[client_interceptors.go](./client_interceptors.go) [context.go](./context.go) [doc.go](./doc.go) [grpclogger.go](./grpclogger.go) [noop.go](./noop.go) [options.go](./options.go) [payload_interceptors.go](./payload_interceptors.go) [server_interceptors.go](./server_interceptors.go)
15368

logging/logrus/examples_test.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Copyright 2017 Michal Witkowski. All Rights Reserved.
2-
// See LICENSE for licensing terms.
3-
41
package grpc_logrus_test
52

63
import (
@@ -16,8 +13,13 @@ import (
1613
"google.golang.org/grpc"
1714
)
1815

16+
var (
17+
logrusLogger *logrus.Logger
18+
customFunc grpc_logrus.CodeToLevel
19+
)
20+
1921
// Initialization shows a relatively complex initialization sequence.
20-
func Example_initialization(logrusLogger *logrus.Logger, customFunc grpc_logrus.CodeToLevel) *grpc.Server {
22+
func Example_Initialization() {
2123
// Logrus entry is used, allowing pre-definition of certain fields by the user.
2224
logrusEntry := logrus.NewEntry(logrusLogger)
2325
// Shared options for the logger, with a custom gRPC code to log level function.
@@ -27,7 +29,7 @@ func Example_initialization(logrusLogger *logrus.Logger, customFunc grpc_logrus.
2729
// Make sure that log statements internal to gRPC library are logged using the zapLogger as well.
2830
grpc_logrus.ReplaceGrpcLogger(logrusEntry)
2931
// Create a server, make sure we put the grpc_ctxtags context before everything else.
30-
server := grpc.NewServer(
32+
_ = grpc.NewServer(
3133
grpc_middleware.WithUnaryServerChain(
3234
grpc_ctxtags.UnaryServerInterceptor(grpc_ctxtags.WithFieldExtractor(grpc_ctxtags.CodeGenRequestFieldExtractor)),
3335
grpc_logrus.UnaryServerInterceptor(logrusEntry, opts...),
@@ -37,10 +39,9 @@ func Example_initialization(logrusLogger *logrus.Logger, customFunc grpc_logrus.
3739
grpc_logrus.StreamServerInterceptor(logrusEntry, opts...),
3840
),
3941
)
40-
return server
4142
}
4243

43-
func Example_initializationWithDurationFieldOverride(logrusLogger *logrus.Logger) *grpc.Server {
44+
func Example_InitializationWithDurationFieldOverride() {
4445
// Logrus entry is used, allowing pre-definition of certain fields by the user.
4546
logrusEntry := logrus.NewEntry(logrusLogger)
4647
// Shared options for the logger, with a custom duration to log field function.
@@ -49,7 +50,7 @@ func Example_initializationWithDurationFieldOverride(logrusLogger *logrus.Logger
4950
return "grpc.time_ns", duration.Nanoseconds()
5051
}),
5152
}
52-
server := grpc.NewServer(
53+
_ = grpc.NewServer(
5354
grpc_middleware.WithUnaryServerChain(
5455
grpc_ctxtags.UnaryServerInterceptor(),
5556
grpc_logrus.UnaryServerInterceptor(logrusEntry, opts...),
@@ -59,12 +60,11 @@ func Example_initializationWithDurationFieldOverride(logrusLogger *logrus.Logger
5960
grpc_logrus.StreamServerInterceptor(logrusEntry, opts...),
6061
),
6162
)
62-
return server
6363
}
6464

6565
// Simple unary handler that adds custom fields to the requests's context. These will be used for all log statements.
66-
func Example_handlerUsageUnaryPing() interface{} {
67-
x := func(ctx context.Context, ping *pb_testproto.PingRequest) (*pb_testproto.PingResponse, error) {
66+
func Example_HandlerUsageUnaryPing() {
67+
_ = func(ctx context.Context, ping *pb_testproto.PingRequest) (*pb_testproto.PingResponse, error) {
6868
// Add fields the ctxtags of the request which will be added to all extracted loggers.
6969
grpc_ctxtags.Extract(ctx).Set("custom_tags.string", "something").Set("custom_tags.int", 1337)
7070
// Extract a single request-scoped logrus.Logger and log messages.
@@ -73,5 +73,4 @@ func Example_handlerUsageUnaryPing() interface{} {
7373
l.Info("another ping")
7474
return &pb_testproto.PingResponse{Value: ping.Value}, nil
7575
}
76-
return x
7776
}

0 commit comments

Comments
 (0)