Go current time server for exploring the standard library.
Specifically:
- Implement a Handler (
net/http
) that responds with the current time, usingtime
. Response is either text (default) or json (with request headerAccept: application/json
), making use ofencoding/json
. - Use structured logging (
log/slog
) to log the IP of the requester. Implemented as a middleware function.
$ make run
# On other instance...
# JSON output:
$ curl -i -H "Accept: application/json" http://127.0.0.1:8080/now
# Text output:
$ curl -i http://127.0.0.1:8080/now