https://github.com/samthor/nicehttp
Convenience library for HTTP handlers in Go
https://github.com/samthor/nicehttp
golang golang-library http
Last synced: 7 months ago
JSON representation
Convenience library for HTTP handlers in Go
- Host: GitHub
- URL: https://github.com/samthor/nicehttp
- Owner: samthor
- License: apache-2.0
- Created: 2019-06-24T08:38:37.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-02-13T23:58:06.000Z (almost 6 years ago)
- Last Synced: 2025-02-22T22:23:57.962Z (12 months ago)
- Topics: golang, golang-library, http
- Language: Go
- Homepage: https://godoc.org/github.com/samthor/nicehttp
- Size: 22.5 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Convenience library for HTTP handlers in Go.
These help [@samthor](https://twitter.com/samthor) write servers.
YMMV.
See [the godoc](https://godoc.org/github.com/samthor/nicehttp) for documentation.
## Convenience handler type
The core `Handler` type looks like this and implements `http.Handler`:
```go
type Handler func(ctx context.Context, r *http.Request) interface{}
```
As you write HTTP handlers, you can just return a variety of types to have your HTTP server do something sensible.
If you return an `error`, the server will serve a 500 and `log` the error.
See [the godoc](https://godoc.org/github.com/samthor/nicehttp#Handler) for more supported types.
Yes, this prevents static type checking for your HTTP handlers.
Yes, the convenience is worth it.
## App Engine
The `dev_appserver` script seems to be going away for runtimes of `go112` and beyond, which means your program will no longer read its "app.yaml" in development.
Static handlers will still work in production ¯\_(ツ)_/¯
Run `nicehttp.Serve("app.yaml", nil)` to host your application with:
* static handler support in development, and
* automatic serving on the environment variable `PORT`