mirror of
https://github.com/kataras/iris.git
synced 2025-12-17 09:57:01 +00:00
replace ioutil with io package and other minor improvements
This commit is contained in:
9
cache/browser.go
vendored
9
cache/browser.go
vendored
@@ -49,10 +49,11 @@ var NoCache = func(ctx *context.Context) {
|
||||
// Usage: `app.Use(cache.StaticCache(24 * time.Hour))` or `app.Use(cache.Staticcache(-1))`.
|
||||
// A middleware, which is a simple Handler can be called inside another handler as well, example:
|
||||
// cacheMiddleware := cache.StaticCache(...)
|
||||
// func(ctx iris.Context){
|
||||
// cacheMiddleware(ctx)
|
||||
// [...]
|
||||
// }
|
||||
//
|
||||
// func(ctx iris.Context){
|
||||
// cacheMiddleware(ctx)
|
||||
// [...]
|
||||
// }
|
||||
var StaticCache = func(cacheDur time.Duration) context.Handler {
|
||||
if int64(cacheDur) <= 0 {
|
||||
return NoCache
|
||||
|
||||
6
cache/client/client.go
vendored
6
cache/client/client.go
vendored
@@ -2,7 +2,7 @@ package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
@@ -17,8 +17,8 @@ import (
|
||||
// register one client handler per route.
|
||||
//
|
||||
// it's just calls a remote cache service server/handler,
|
||||
// which lives on other, external machine.
|
||||
//
|
||||
// which lives on other, external machine.
|
||||
type ClientHandler struct {
|
||||
// bodyHandler the original route's handler
|
||||
bodyHandler context.Handler
|
||||
@@ -162,7 +162,7 @@ func (h *ClientHandler) ServeHTTP(ctx *context.Context) {
|
||||
// get the status code , content type and the write the response body
|
||||
ctx.ContentType(response.Header.Get(cfg.ContentTypeHeader))
|
||||
ctx.StatusCode(response.StatusCode)
|
||||
responseBody, err := ioutil.ReadAll(response.Body)
|
||||
responseBody, err := io.ReadAll(response.Body)
|
||||
response.Body.Close()
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
13
cache/client/rule/validator.go
vendored
13
cache/client/rule/validator.go
vendored
@@ -22,12 +22,13 @@ type PreValidator func(*context.Context) bool
|
||||
//
|
||||
// Q: What's the difference between this and a PreValidator?
|
||||
// A: PreValidator runs BEFORE trying to get the cache, it cares only for the request
|
||||
// and if at least one PreValidator returns false then it just runs the original handler and stop there, at the other hand
|
||||
// a PostValidator runs if all PreValidators returns true and original handler is executed but with a response recorder,
|
||||
// also the PostValidator should return true to store the cached response.
|
||||
// Last, a PostValidator accepts a context
|
||||
// in order to be able to catch the original handler's response,
|
||||
// the PreValidator checks only for request.
|
||||
//
|
||||
// and if at least one PreValidator returns false then it just runs the original handler and stop there, at the other hand
|
||||
// a PostValidator runs if all PreValidators returns true and original handler is executed but with a response recorder,
|
||||
// also the PostValidator should return true to store the cached response.
|
||||
// Last, a PostValidator accepts a context
|
||||
// in order to be able to catch the original handler's response,
|
||||
// the PreValidator checks only for request.
|
||||
//
|
||||
// If a function of type of PostValidator returns true then the (shared-always) cache is allowed to be stored.
|
||||
type PostValidator func(*context.Context) bool
|
||||
|
||||
Reference in New Issue
Block a user