Skip to content

Commit

Permalink
new doc: the format after gofmt (#512)
Browse files Browse the repository at this point in the history
Signed-off-by: aimuz <mr.imuz@gmail.com>

Signed-off-by: aimuz <mr.imuz@gmail.com>
  • Loading branch information
aimuz authored Sep 13, 2022
1 parent cb54482 commit 782d4b3
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 22 deletions.
8 changes: 5 additions & 3 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// Licensed under the Apache License 2.0.

/*
Package middleware
`middleware` is a collection of gRPC middleware packages: interceptors, helpers and tools.
Middleware
# Middleware
gRPC is a fantastic RPC middleware, which sees a lot of adoption in the Golang world. However, the
upstream gRPC codebase is relatively bare bones.
Expand All @@ -13,7 +15,7 @@ This package, and most of its child packages provides commonly needed middleware
client-side interceptors for retires, server-side interceptors for input validation and auth,
functions for chaining said interceptors, metadata convenience methods and more.
Chaining
# Chaining
Simple way of turning a multiple interceptors into a single interceptor. Here's an example for
server chaining:
Expand All @@ -39,7 +41,7 @@ These interceptors will be executed from left to right: monitoring and then retr
The retry interceptor will call every interceptor that follows it whenever when a retry happens.
Writing Your Own
# Writing Your Own
Implementing your own interceptor is pretty trivial: there are interfaces for that. But the interesting
bit exposing common data to handlers (and other middleware), similarly to HTTP Middleware design.
Expand Down
4 changes: 3 additions & 1 deletion interceptors/auth/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// Licensed under the Apache License 2.0.

/*
Package auth is a middleware that authenticates incoming gRPC requests.
`auth` a generic server-side auth middleware for gRPC.
Server Side Auth Middleware
# Server Side Auth Middleware
It allows for easy assertion of `:authorization` headers in gRPC calls, be it HTTP Basic auth, or
OAuth2 Bearer tokens.
Expand Down
4 changes: 2 additions & 2 deletions interceptors/logging/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ All logging middleware will emit a final log statement. It is based on the error
the gRPC status code, an error (if any) and it emits at a level controlled via `WithLevels`. You can control this behavior
using `WithDecider`.
This parent package
# This parent package
This particular package is intended for use by other middleware, logging or otherwise. It contains interfaces that other
logging middlewares *could* share. This allows code to be shared between different implementations.
Field names
# Field names
All field names of loggers follow the OpenTracing semantics definitions, with `grpc.` prefix if needed:
https://github.com/opentracing/specification/blob/master/semantic_conventions.md
Expand Down
4 changes: 3 additions & 1 deletion interceptors/ratelimit/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// Licensed under the Apache License 2.0.

/*
Package ratelimit is a middleware that limits the rate of requests.
`ratelimit` a generic server-side ratelimit middleware for gRPC.
Server Side Ratelimit Middleware
# Server Side Ratelimit Middleware
It allows to do grpc rate limit by your own rate limiter (e.g. token bucket, leaky bucket, etc.)
Expand Down
4 changes: 3 additions & 1 deletion interceptors/recovery/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
// See LICENSE for licensing terms.

/*
Package recovery is a middleware that recovers from panics and logs the panic message.
`recovery` are interceptors that recover from gRPC handler panics.
Server Side Recovery Middleware
# Server Side Recovery Middleware
By default a panic will be converted into a gRPC error with `code.Internal`.
Expand Down
4 changes: 2 additions & 2 deletions interceptors/retry/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
/*
Package retry provides client-side request retry logic for gRPC.
Client-Side Request Retry Interceptor
# Client-Side Request Retry Interceptor
It allows for automatic retry, inside the generated gRPC code of requests based on the gRPC status
of the reply. It supports unary (1:1), and server stream (1:n) requests.
By default the interceptors *are disabled*, preventing accidental use of retries. You can easily
override the number of retries (setting them to more than 0) with a `grpc.ClientOption`, e.g.:
myclient.Ping(ctx, goodPing, grpc_retry.WithMax(5))
myclient.Ping(ctx, goodPing, grpc_retry.WithMax(5))
Other default options are: retry on `ResourceExhausted` and `Unavailable` gRPC codes, use a 50ms
linear backoff with 10% jitter.
Expand Down
2 changes: 2 additions & 0 deletions interceptors/skip/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Licensed under the Apache License 2.0.

/*
Package skip
`skip` allow users to skip interceptors in certain condition.
Users can use grpc type, service name, method name and metadata to determine whether to skip the interceptor.
Expand Down
4 changes: 3 additions & 1 deletion interceptors/timeout/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// Licensed under the Apache License 2.0.

/*
Package timeout is a middleware that responds with a timeout error after the given duration.
`grpc_timeout` are interceptors that timeout for gRPC client calls.
Client Side Timeout Middleware
# Client Side Timeout Middleware
Please see examples for simple examples of use.
*/
Expand Down
5 changes: 3 additions & 2 deletions interceptors/validator/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// Licensed under the Apache License 2.0.

/*
Package validator
`validator` is a generic request contents validator server-side middleware for gRPC.
Request Validator Middleware
# Request Validator Middleware
Validating input is important, and hard. It also causes a lot of boilerplate code. This middleware
checks for the existence of a `Validate` method on each of the messages of a gRPC request. This
Expand All @@ -16,7 +18,6 @@ While it is generic, it was intended to be used with https://github.com/mwitkow/
a Go protocol buffers codegen plugin that creates the `Validate` methods (including nested messages)
based on declarative options in the `.proto` files themselves. For example:
syntax = "proto3";
package validator.examples;
import "github.com/mwitkow/go-proto-validators/validator.proto";
Expand Down
4 changes: 2 additions & 2 deletions providers/kit/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the Apache License 2.0.

/*
`kit` provides a small adapter required to use go-kit/log in logging gRPC middlewares.
Please see examples for examples of use.
Package kit provides a small adapter required to use go-kit/log in logging gRPC middlewares.
Please see examples for examples of use.
*/
package kit
5 changes: 2 additions & 3 deletions providers/logr/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// Licensed under the Apache License 2.0.

/*
`logr` provides a small adapter required to use logr in logging gRPC middlewares.
Please see examples for examples of use.
Package logr provides a small adapter required to use logr in logging gRPC middlewares.
Please see examples for examples of use.
*/
package logr
4 changes: 2 additions & 2 deletions providers/logrus/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the Apache License 2.0.

/*
`logrus` provides a small adapter required to use logrus in logging gRPC middlewares.
Please see examples for examples of use.
Package logrus provides a small adapter required to use logrus in logging gRPC middlewares.
Please see examples for examples of use.
*/
package logrus
4 changes: 2 additions & 2 deletions providers/zap/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the Apache License 2.0.

/*
`zap` provides a small adapter required to use zap in logging gRPC middlewares.
Please see examples for examples of use.
Package zap provides a small adapter required to use zap in logging gRPC middlewares.
Please see examples for examples of use.
*/
package zap

0 comments on commit 782d4b3

Please sign in to comment.