-
Notifications
You must be signed in to change notification settings - Fork 49
/
souin.go
61 lines (54 loc) · 1.35 KB
/
souin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package souin
import (
"net/http"
"time"
"github.com/darkweak/souin/configurationtypes"
"github.com/darkweak/souin/pkg/middleware"
)
var (
DefaultConfiguration = middleware.BaseConfiguration{
DefaultCache: &configurationtypes.DefaultCache{
TTL: configurationtypes.Duration{
Duration: 10 * time.Second,
},
},
LogLevel: "info",
}
DevDefaultConfiguration = middleware.BaseConfiguration{
API: configurationtypes.API{
BasePath: "/souin-api",
Prometheus: configurationtypes.APIEndpoint{
Enable: true,
},
Souin: configurationtypes.APIEndpoint{
Enable: true,
},
},
DefaultCache: &configurationtypes.DefaultCache{
Regex: configurationtypes.Regex{
Exclude: "/excluded",
},
TTL: configurationtypes.Duration{
Duration: 5 * time.Second,
},
},
LogLevel: "debug",
}
)
// SouinGoZeroMiddleware declaration.
type SouinGozeroMiddleware struct {
*middleware.SouinBaseHandler
}
func NewHTTPCache(c middleware.BaseConfiguration) *SouinGozeroMiddleware {
return &SouinGozeroMiddleware{
SouinBaseHandler: middleware.NewHTTPCacheHandler(&c),
}
}
func (s *SouinGozeroMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
return func(rw http.ResponseWriter, r *http.Request) {
_ = s.SouinBaseHandler.ServeHTTP(rw, r, func(w http.ResponseWriter, r *http.Request) error {
next(w, r)
return nil
})
}
}