gor
is a lightweight router for creating Go HTTP services. It helps build large REST API services that can be maintained as the project grows.
gor
is built on the context package.
See examples
go get -u github.com/pchchv/gor
gor comes with an optional middleware
package that provides a set of standard net/http
middleware.
Any middleware in the ecosystem that is also compatible with net/http
can be used with gor's mux.
gor/middleware Handler | description |
---|---|
AllowContentEncoding | Provides a white list of Content-Encoding headers of the request |
AllowContentType | Explicit white list of accepted Content-Types requests |
BasicAuth | Basic HTTP authentication |
Compress | Gzip compression for clients accepting compressed responses |
ContentCharset | Providing encoding for Content-Type request headers |
CleanPath | Clean the double slashes from request path |
GetHead | Automatically route undefined HEAD requests to GET handlers |
Heartbeat | Monitoring endpoint to check the pulse of the servers |
Logger | Logs the start and end of each request with the elapsed processing time |
NoCache | Sets response headers to prevent caching by clients |
Profiler | Simple net/http/pprof connection to routers |
RealIP | Sets RemoteAddr http.Request to X-Real-IP or X-Forwarded-For |
Recoverer | Gracefully absorbs panic and prints a stack trace |
RequestID | Injects a request ID in the context of each request |
RedirectSlashes | Redirect slashes in routing paths |
RouteHeaders | Handling routes for request headers |
SetHeader | Middleware to set the key/response header value |
StripSlashes | Strip slashes in routing paths |
Throttle | Puts a ceiling on the number of concurrent requests |
Timeout | Signals to the request context that the timeout deadline has been reached |
URLFormat | Parse the extension from the url and put it in the request context |
WithValue | Middleware to set the key/value in the context of a request |
context
is a tiny package available in stdlib since go1.7, providing a simple interface for context signaling via call stacks and goroutines.
Learn more at The Go Blog