Table of Contents
Month 5 · Week 2 — Exercises (interceptors, metadata, transcoding)¶
Standard-library-only Go packages with table-driven tests. They rebuild the
mechanics that gRPC middleware relies on — interceptor composition, metadata
multi-maps, and grpc-gateway path templates — so go test runs anywhere with
no protoc, no google.golang.org/grpc, and no network.
How to run¶
go test ./exercises/month-05/week-2/...
# or one at a time, verbose:
go test -v ./exercises/month-05/week-2/chain
Prompts¶
-
chain/— ImplementChain(...Interceptor) Interceptorthat composes unary interceptors sointerceptors[0]is the OUTERMOST layer (first in, last out), the final handler sits in the middle, and an interceptor can short-circuit by not callingnext. Context changes must propagate inward. Concepts: middleware composition, the onion model,grpc.ChainUnaryInterceptor(Day 120). -
metadata/— Implement anMD(gRPCmetadata.MD) multi-map with CASE-INSENSITIVE keys (Set/Append/Get/New) and aParseBearerthat pulls the token out of anAuthorization: Bearer <token>header (case-insensitive scheme, trimmed,ErrNoTokenon failure). Concepts: HTTP/2 header case-insensitivity, metadata propagation, auth interceptors (Day 121). -
pathtemplate/— Implement grpc-gateway path matching:Parsea template like/v1/users/{id}/books/{book_id}andMatchrequest paths, extracting the{name}parameters into a map. Reject{}(ErrEmptyParam); ignore leading/trailing slashes; non-match returns(nil, false). Concepts: REST transcoding, path-parameter extraction (Day 123).
Results¶
| Exercise | Focus | go test |
|---|---|---|
chain |
interceptor composition / ordering | ✅ |
metadata |
case-insensitive metadata + bearer parsing | ✅ |
pathtemplate |
grpc-gateway path templates | ✅ |