-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathapp.go
More file actions
94 lines (77 loc) · 2.25 KB
/
Copy pathapp.go
File metadata and controls
94 lines (77 loc) · 2.25 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package httpcache
import (
"github.com/caddyserver/caddy/v2"
"github.com/darkweak/souin/configurationtypes"
"github.com/darkweak/souin/pkg/storage/types"
"github.com/darkweak/souin/pkg/surrogate/providers"
"github.com/darkweak/storages/core"
)
type notifierItem struct {
API configurationtypes.API
SurrogateStorage providers.SurrogateInterface
}
// SouinApp contains the whole Souin necessary items
type SouinApp struct {
DefaultCache
// The provider to use.
Storers []types.Storer
// Surrogate storage to support the configuration reload without surrogate-key data loss.
SurrogateStorage providers.SurrogateInterface
// SurrogateKeyDisabled opt-out the Surrogate key system.
SurrogateKeyDisabled bool
// Cache-key tweaking.
CacheKeys configurationtypes.CacheKeys `json:"cache_keys,omitempty"`
// API endpoints enablers.
API configurationtypes.API `json:"api,omitempty"`
// Logger level, fallback on caddy's one when not redefined.
LogLevel string `json:"log_level,omitempty"`
notifier chan notifierItem
}
func init() {
caddy.RegisterModule(new(SouinApp))
}
// Provision implements caddy.Provisioner
func (s *SouinApp) Provision(_ caddy.Context) error {
if s.notifier == nil {
s.notifier = make(chan notifierItem, 1)
}
return nil
}
// Start will start the App
func (s SouinApp) Start() error {
_, _ = up.Delete(stored_providers_key)
_, _ = up.LoadOrStore(stored_providers_key, newStorageProvider())
return nil
}
// Stop will stop the App
func (s SouinApp) Stop() error {
core.ResetRegisteredStorages()
return nil
}
// CaddyModule implements caddy.ModuleInfo
func (s SouinApp) CaddyModule() caddy.ModuleInfo {
return caddy.ModuleInfo{
ID: moduleName,
New: func() caddy.Module { return new(SouinApp) },
}
}
func (s *SouinApp) withSurrogateStorer(surrogate providers.SurrogateInterface) {
defer close(s.notifier)
s.SurrogateStorage = surrogate
s.notifier <- notifierItem{
API: s.API,
SurrogateStorage: surrogate,
}
}
func (s *SouinApp) Validate() error {
return nil
}
func (s *SouinApp) onMiddlewareLoaded() chan notifierItem {
return s.notifier
}
var (
_ caddy.App = (*SouinApp)(nil)
_ caddy.Module = (*SouinApp)(nil)
_ caddy.Provisioner = (*SouinApp)(nil)
_ caddy.Validator = (*SouinApp)(nil)
)