{"modulePath":"github.com/xaionaro-go/picapi","version":"v0.0.0-20190907075849-7f3e19902875","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package middlewares\n\n## Constants\n\n```go\nconst (\n\t// CacheRecentRatio is the fraction of recently added entries in the cache\n\t//\n\t// See more at https://godoc.org/github.com/hashicorp/golang-lru#pkg-constants\n\tCacheRecentRatio = 0.15\n\n\t// CacheGhostRatio is the fraction of ghost entries in the cache\n\t//\n\t// See more at https://godoc.org/github.com/hashicorp/golang-lru#pkg-constants\n\tCacheGhostRatio = 0.5\n)\n```\n\n## Variables\n\n```go\nvar (\n\t// ErrCacheItemExpired is returned when it was called an `Apply()` on an expired cache item.\n\tErrCacheItemExpired = errors.New(`cache item has expired`)\n)\n```\n\n## Functions\n\n```go\nfunc AccessLogger(logger Printfer, handler fasthttp.RequestHandler) fasthttp.RequestHandler\n```\nAccessLogger wraps the \\`handler\\` to log requests via \\`logger\\` (like \\`access.log\\`)\n\n```go\nfunc Cache(\n\tmaxEntries uint64,\n\tmaxEntrySize uint64,\n\tmaxDuration time.Duration,\n\thandler fasthttp.RequestHandler,\n) fasthttp.RequestHandler\n```\nCache 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\\`.\n\nTo limit memory usage there're parameters \\`maxEntries\\` and \\`maxEntrySize\\`. Total consumed memory (by this middleware) could be estimated as \\`maxEntries \\* maxEntrySize\\`.\n\nAlso this middleware controls HTTP header \\`Cache-Control\\` to ask a browser to cache the response on it's side, too.\n\nIf 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.\n\n```go\nfunc RecoverPanic(handler fasthttp.RequestHandler) fasthttp.RequestHandler\n```\nRecoverPanic recovers panics in the \\`handler\\` and returns \\`500 Internal Server Error\\` if a panic occurs.\n\n## Types\n\n```go\ntype Printfer interface {\n\t// Printf is a pretty-standart `Printf` (`fmt` is the format and `args` are the arguments for the format).\n\t//\n\t// For example you can use `log.New` as `Printfer`.\n\tPrintf(fmt string, args ...interface{})\n}\n```\nPrintfer is a simple logger interface for \\`NewHTTPServer\\`\n\n","path":"github.com/xaionaro-go/picapi/httpserver/middlewares","name":"middlewares","synopsis":"","isRedistributable":true}
