-
Notifications
You must be signed in to change notification settings - Fork 24
/
app.go
59 lines (51 loc) · 1.51 KB
/
app.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
package httpcache
import (
"errors"
"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"
)
// SouinApp contains the whole Souin necessary items
type SouinApp struct {
DefaultCache
// The provider to use.
Storers []types.Storer
// Surrogate storage to support th econfiguration reload without surrogate-key data loss.
SurrogateStorage providers.SurrogateInterface
// 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"`
}
func init() {
caddy.RegisterModule(SouinApp{})
}
// Start will start the App
func (s SouinApp) Start() error {
core.ResetRegisteredStorages()
_, _ = up.Delete(stored_providers_key)
_, _ = up.LoadOrStore(stored_providers_key, newStorageProvider())
if s.DefaultCache.GetTTL() == 0 {
return errors.New("Invalid/Incomplete default cache declaration")
}
return nil
}
// Stop will stop the App
func (s SouinApp) Stop() error {
return nil
}
// CaddyModule implements caddy.ModuleInfo
func (s SouinApp) CaddyModule() caddy.ModuleInfo {
return caddy.ModuleInfo{
ID: moduleName,
New: func() caddy.Module { return new(SouinApp) },
}
}
var (
_ caddy.App = (*SouinApp)(nil)
_ caddy.Module = (*SouinApp)(nil)
)