https://github.com/matttproud/contextualizing-contexts
Demonstrate and explain vagaries of Go's context API.
https://github.com/matttproud/contextualizing-contexts
go grpc grpc-go http
Last synced: 3 months ago
JSON representation
Demonstrate and explain vagaries of Go's context API.
- Host: GitHub
- URL: https://github.com/matttproud/contextualizing-contexts
- Owner: matttproud
- License: apache-2.0
- Created: 2024-07-20T14:44:42.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-22T14:39:26.000Z (almost 2 years ago)
- Last Synced: 2025-04-07T05:49:37.298Z (about 1 year ago)
- Topics: go, grpc, grpc-go, http
- Language: Go
- Homepage: https://matttproud.com
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
This repository contains code samples to demonstrate vagaries around Go's
context API.
## Structure
* `{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-series` run 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-synth` demonstrates a deadline with the HTTP stack using
a homegrown `X-MTP-Deadline` request header (uses `http.TimeFormat` values).
```
$ 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}` and `http-deadline-synth` into 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].
[`grpc_cli`]: https://github.com/grpc/grpc/blob/master/doc/command_line_tool.md
[no default timeout/deadline]: https://grpc.io/docs/guides/deadlines/#deadlines-on-the-client