This repository contains code samples to demonstrate vagaries around Go's context API.
-
{grpc,http}-in-series: shows the behavior of a function with manual deadline management juxtaposed with the context's native cancellation mechanisms as implemented respectively through gRPC and HTTP server libraries. -
{grpc,http}-branch: shows the behavior of the same function from{grpc,http}-in-seriesrun in a separate goroutine from the respective server libraries to connect how the server's dispatch functions handle context lifetime. -
{grpc,http}-notify: shows the lifetime behaviors of the context from the respective server libraries to establish when lifetime begins and ends in isolation. -
{grpc,http}-deadline: reveals what deadline the server library attaches to the context (if any).http-deadline-synthdemonstrates a deadline with the HTTP stack using a homegrownX-MTP-Deadlinerequest header (useshttp.TimeFormatvalues).$ curl -H "X-MTP-Deadline: $(LC_ALL=C TZ=GMT date -d 'now + 1 minutes' '+%a, %d %b %Y %T %Z')" localhost:8080 -
{grpc,http}-complete: these combine respectively{grpc,http}-{branch,deadline,notify}andhttp-deadline-synthinto one server to show you all of the moving parts of the original quiz.
The server samples serve on localhost:8080:
-
Clients can exercise the HTTP servers with curl:
$ curl localhost:8080 -
Clients can exercise the gRPC servers the gRPC CLI (
grpc_cli):$ grpc_cli call localhost:8080 proto.Test.Exercise ''
Try exercising the gRPC servers with varying values of the grpc_cli's
--timeout flag. There is no default timeout/deadline.