Documentation ¶
Index ¶
- Constants
- Variables
- func AccessLogger(logger Printfer, handler fasthttp.RequestHandler) fasthttp.RequestHandler
- func Cache(maxEntries uint64, maxEntrySize uint64, maxDuration time.Duration, ...) fasthttp.RequestHandler
- func RecoverPanic(handler fasthttp.RequestHandler) fasthttp.RequestHandler
- type Printfer
Constants ¶
const ( // CacheRecentRatio is the fraction of recently added entries in the cache // // See more at https://godoc.org/github.com/hashicorp/golang-lru#pkg-constants CacheRecentRatio = 0.15 // CacheGhostRatio is the fraction of ghost entries in the cache // // See more at https://godoc.org/github.com/hashicorp/golang-lru#pkg-constants CacheGhostRatio = 0.5 )
Variables ¶
var ( // ErrCacheItemExpired is returned when it was called an `Apply()` on an expired cache item. ErrCacheItemExpired = errors.New(`cache item has expired`) )
Functions ¶
func AccessLogger ¶
func AccessLogger(logger Printfer, handler fasthttp.RequestHandler) fasthttp.RequestHandler
AccessLogger wraps the `handler` to log requests via `logger` (like `access.log`)
func Cache ¶
func Cache( maxEntries uint64, maxEntrySize uint64, maxDuration time.Duration, handler fasthttp.RequestHandler, ) fasthttp.RequestHandler
Cache wraps the `handler` returns a new handler which will cache responses (and return responses from the cache if there's an actual record) for a time interval `maxDuration`.
To limit memory usage there're parameters `maxEntries` and `maxEntrySize`. Total consumed memory (by this middleware) could be estimated as `maxEntries * maxEntrySize`.
Also this middleware controls HTTP header `Cache-Control` to ask a browser to cache the response on it's side, too.
If there were received two similar (with the same URI) concurrent requests then it will wait for the execution of one of them then will just return the cached value to the second one.
func RecoverPanic ¶
func RecoverPanic(handler fasthttp.RequestHandler) fasthttp.RequestHandler
RecoverPanic recovers panics in the `handler` and returns `500 Internal Server Error` if a panic occurs.
Types ¶
type Printfer ¶
type Printfer interface { // Printf is a pretty-standart `Printf` (`fmt` is the format and `args` are the arguments for the format). // // For example you can use `log.New` as `Printfer`. Printf(fmt string, args ...interface{}) }
Printfer is a simple logger interface for `NewHTTPServer`