Skip to content

Commit

Permalink
bump storages to v0.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
darkweak committed Aug 12, 2024
1 parent 05059d3 commit e19c417
Show file tree
Hide file tree
Showing 104 changed files with 1,687 additions and 1,626 deletions.
6 changes: 3 additions & 3 deletions configurationtypes/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"time"

"go.uber.org/zap"
"github.com/darkweak/storages/core"
yaml "gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -439,8 +439,8 @@ type AbstractConfigurationInterface interface {
GetDefaultCache() DefaultCacheInterface
GetAPI() API
GetLogLevel() string
GetLogger() *zap.Logger
SetLogger(*zap.Logger)
GetLogger() core.Logger
SetLogger(core.Logger)
GetYkeys() map[string]SurrogateKeys
GetSurrogateKeys() map[string]SurrogateKeys
GetCacheKeys() CacheKeys
Expand Down
2 changes: 1 addition & 1 deletion context/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (cc *cacheContext) SetupContext(c configurationtypes.AbstractConfigurationI
if c.GetDefaultCache().GetCacheName() != "" {
cc.cacheName = c.GetDefaultCache().GetCacheName()
}
c.GetLogger().Sugar().Debugf("Set %s as Cache-Status name", cc.cacheName)
c.GetLogger().Debugf("Set %s as Cache-Status name", cc.cacheName)
}

func (cc *cacheContext) SetContext(req *http.Request) *http.Request {
Expand Down
9 changes: 5 additions & 4 deletions context/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/darkweak/souin/configurationtypes"
"github.com/darkweak/storages/core"
"go.uber.org/zap"
)

Expand All @@ -29,10 +30,10 @@ func (*testConfiguration) GetAPI() configurationtypes.API {
func (*testConfiguration) GetLogLevel() string {
return ""
}
func (*testConfiguration) GetLogger() *zap.Logger {
return zap.NewNop()
func (*testConfiguration) GetLogger() core.Logger {
return zap.NewNop().Sugar()
}
func (*testConfiguration) SetLogger(*zap.Logger) {
func (*testConfiguration) SetLogger(core.Logger) {
}
func (*testConfiguration) GetYkeys() map[string]configurationtypes.SurrogateKeys {
return nil
Expand All @@ -49,7 +50,7 @@ func Test_CacheContext_SetupContext(t *testing.T) {
c := testConfiguration{
defaultCache: &dc,
}
c.SetLogger(zap.NewNop())
c.SetLogger(zap.NewNop().Sugar())
ctx := cacheContext{}

ctx.SetupContext(&c)
Expand Down
2 changes: 1 addition & 1 deletion context/graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func Test_GraphQLContext_SetContext(t *testing.T) {
c := testConfiguration{
defaultCache: &dc,
}
c.SetLogger(zap.NewNop())
c.SetLogger(zap.NewNop().Sugar())
ctx := graphQLContext{custom: true}

req := httptest.NewRequest(http.MethodGet, "http://domain.com", nil)
Expand Down
2 changes: 1 addition & 1 deletion context/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (m *methodContext) SetupContext(c configurationtypes.AbstractConfigurationI
m.allowedVerbs = c.GetDefaultCache().GetAllowedHTTPVerbs()
m.custom = true
}
c.GetLogger().Sugar().Debugf("Allow %d method(s). %v.", len(m.allowedVerbs), m.allowedVerbs)
c.GetLogger().Debugf("Allow %d method(s). %v.", len(m.allowedVerbs), m.allowedVerbs)
}

func (m *methodContext) SetContext(req *http.Request) *http.Request {
Expand Down
4 changes: 2 additions & 2 deletions context/method_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func Test_MethodContext_SetupContext(t *testing.T) {
c := testConfiguration{
defaultCache: &dc,
}
c.SetLogger(zap.NewNop())
c.SetLogger(zap.NewNop().Sugar())
ctx := methodContext{}

ctx.SetupContext(&c)
Expand All @@ -34,7 +34,7 @@ func Test_MethodContext_SetContext(t *testing.T) {
c := testConfiguration{
defaultCache: &dc,
}
c.SetLogger(zap.NewNop())
c.SetLogger(zap.NewNop().Sugar())
ctx := methodContext{}
c.defaultCache.AllowedHTTPVerbs = []string{http.MethodGet, http.MethodHead}
ctx.SetupContext(&c)
Expand Down
2 changes: 1 addition & 1 deletion context/mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (mc *ModeContext) SetupContext(c configurationtypes.AbstractConfigurationIn
mc.Bypass_request = mode == "bypass" || mode == "bypass_request"
mc.Bypass_response = mode == "bypass" || mode == "bypass_response"
mc.Strict = !mc.Bypass_request && !mc.Bypass_response
c.GetLogger().Sugar().Debugf("The cache logic will run as %s: %+v", mode, mc)
c.GetLogger().Debugf("The cache logic will run as %s: %+v", mode, mc)
}

func (mc *ModeContext) SetContext(req *http.Request) *http.Request {
Expand Down
2 changes: 1 addition & 1 deletion context/mode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func Test_ModeContext_SetupContext(t *testing.T) {
c := testConfiguration{
defaultCache: &dc,
}
c.SetLogger(zap.NewNop())
c.SetLogger(zap.NewNop().Sugar())
ctx := ModeContext{}

ctx.SetupContext(&c)
Expand Down
4 changes: 2 additions & 2 deletions context/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func (t *timeoutContext) SetupContext(c configurationtypes.AbstractConfiguration
if c.GetDefaultCache().GetTimeout().Backend.Duration != 0 {
t.timeoutBackend = c.GetDefaultCache().GetTimeout().Backend.Duration
}
c.GetLogger().Sugar().Infof("Set backend timeout to %v", t.timeoutBackend)
c.GetLogger().Sugar().Infof("Set cache timeout to %v", t.timeoutBackend)
c.GetLogger().Infof("Set backend timeout to %v", t.timeoutBackend)
c.GetLogger().Infof("Set cache timeout to %v", t.timeoutBackend)
}

func (t *timeoutContext) SetContext(req *http.Request) *http.Request {
Expand Down
4 changes: 2 additions & 2 deletions context/timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func Test_TimeoutContext_SetupContext(t *testing.T) {
c := testConfiguration{
defaultCache: &dc,
}
c.SetLogger(zap.NewNop())
c.SetLogger(zap.NewNop().Sugar())
ctx := timeoutContext{}

ctx.SetupContext(&c)
Expand Down Expand Up @@ -61,7 +61,7 @@ func Test_TimeoutContext_SetContext(t *testing.T) {
c := testConfiguration{
defaultCache: &dc,
}
c.SetLogger(zap.NewNop())
c.SetLogger(zap.NewNop().Sugar())
ctx := timeoutContext{}
ctx.SetupContext(&c)

Expand Down
6 changes: 3 additions & 3 deletions context/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func Test_Context_Init(t *testing.T) {
c := testConfiguration{
defaultCache: &dc,
}
c.SetLogger(zap.NewNop())
c.SetLogger(zap.NewNop().Sugar())
co := GetContext()

co.Init(&c)
Expand All @@ -31,7 +31,7 @@ func Test_Context_SetContext(t *testing.T) {
c := testConfiguration{
defaultCache: &dc,
}
c.SetLogger(zap.NewNop())
c.SetLogger(zap.NewNop().Sugar())
co := GetContext()

co.Init(&c)
Expand All @@ -58,7 +58,7 @@ func Test_Context_SetBaseContext(t *testing.T) {
c := testConfiguration{
defaultCache: &dc,
}
c.SetLogger(zap.NewNop())
c.SetLogger(zap.NewNop().Sugar())
co := GetContext()

co.Init(&c)
Expand Down
13 changes: 6 additions & 7 deletions docs/website/content/docs/storages/add-own.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Your `struct` must implement it to be a valid storer and be registered in the st

By convention we declare a `Factory` function that respects this signature:
```go
func(providerConfiguration core.CacheProvider, logger *zap.Logger, stale time.Duration) (core.Storer, error)
func(providerConfiguration core.CacheProvider, logger core.Logger, stale time.Duration) (core.Storer, error)
```

And the `Storer` interface is the following:
Expand Down Expand Up @@ -47,18 +47,17 @@ import (

"github.com/darkweak/souin/pkg/storage/types"
"github.com/darkweak/storages/core"
"go.uber.org/zap"
)

// custom storage provider type
type customStorage struct {
m *sync.Map
stale time.Duration
logger *zap.Logger
logger core.Logger
}

// Factory function create new custom storage instance
func Factory(_ core.CacheProvider, logger *zap.Logger, stale time.Duration) (types.Storer, error) {
func Factory(_ core.CacheProvider, logger core.Logger, stale time.Duration) (types.Storer, error) {
return &customStorage{m: &sync.Map{}, logger: logger, stale: stale}, nil
}
```
Expand Down Expand Up @@ -164,7 +163,7 @@ func (provider *customStorage) SetMultiLevel(baseKey, variedKey string, value []
var e error
compressed := new(bytes.Buffer)
if _, e = lz4.NewWriter(compressed).ReadFrom(bytes.NewReader(value)); e != nil {
provider.logger.Sugar().Errorf("Impossible to compress the key %s into Badger, %v", variedKey, e)
provider.logger.Errorf("Impossible to compress the key %s into Badger, %v", variedKey, e)
return e
}

Expand All @@ -182,7 +181,7 @@ func (provider *customStorage) SetMultiLevel(baseKey, variedKey string, value []
return e
}

provider.logger.Sugar().Debugf("Store the new mapping for the key %s in customStorage", variedKey)
provider.logger.Debugf("Store the new mapping for the key %s in customStorage", variedKey)
provider.m.Store(mappingKey, val)
return nil
}
Expand Down Expand Up @@ -233,7 +232,7 @@ After that you'll be able to register your storage using
// anywhere.go
...
logger, _ := zap.NewProduction()
customStorage, _ := your_package.Factory(core.CacheProvider{}, logger, time.Hour)
customStorage, _ := your_package.Factory(core.CacheProvider{}, logger.Sugar(), time.Hour)
// It will register as `YOUR_CUSTOM_STORAGE-THE_UUID`.
core.RegisterStorage(customStorage)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22.1
require (
github.com/caddyserver/caddy/v2 v2.8.4
github.com/cespare/xxhash/v2 v2.2.0
github.com/darkweak/storages/core v0.0.6-0.20240731100357-2a602dafc881
github.com/darkweak/storages/core v0.0.6
github.com/google/uuid v1.6.0
github.com/pierrec/lz4/v4 v4.1.21
github.com/pquerna/cachecontrol v0.2.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/darkweak/go-esi v0.0.5 h1:b9LHI8Tz46R+i6p8avKPHAIBRQUCZDebNmKm5w/Zrns=
github.com/darkweak/go-esi v0.0.5/go.mod h1:koCJqwum1u6mslyZuq/Phm6hfG1K3ZK5Y7jrUBTH654=
github.com/darkweak/storages/core v0.0.6-0.20240731100357-2a602dafc881 h1:WsLHVD+WDxYh5SuZzpZXnhnDruZVrrvnYsHw08izs1s=
github.com/darkweak/storages/core v0.0.6-0.20240731100357-2a602dafc881/go.mod h1:mWN/TO5aLYt2jK6EweZ4JFXXPYmYwYFUQ4YBuIlBkpc=
github.com/darkweak/storages/core v0.0.6 h1:Yj0Z98HsC9Kd9cmjAXLagx6aU7AtXuL++RV2W+FSjc0=
github.com/darkweak/storages/core v0.0.6/go.mod h1:ajTpB9IFLRIRY0EEFLjM5vtsrcNTh+TJK9yRxgG5/wY=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
8 changes: 4 additions & 4 deletions pkg/middleware/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package middleware

import (
"github.com/darkweak/souin/configurationtypes"
"go.uber.org/zap"
"github.com/darkweak/storages/core"
)

// BaseConfiguration holder
Expand All @@ -12,7 +12,7 @@ type BaseConfiguration struct {
CacheKeys configurationtypes.CacheKeys `json:"cache_keys" yaml:"cache_keys"`
URLs map[string]configurationtypes.URL `json:"urls" yaml:"urls"`
LogLevel string `json:"log_level" yaml:"log_level"`
Logger *zap.Logger
Logger core.Logger
PluginName string
Ykeys map[string]configurationtypes.SurrogateKeys `json:"ykeys" yaml:"ykeys"`
SurrogateKeys map[string]configurationtypes.SurrogateKeys `json:"surrogate_keys" yaml:"surrogate_keys"`
Expand Down Expand Up @@ -44,12 +44,12 @@ func (c *BaseConfiguration) GetLogLevel() string {
}

// GetLogger get the logger
func (c *BaseConfiguration) GetLogger() *zap.Logger {
func (c *BaseConfiguration) GetLogger() core.Logger {
return c.Logger
}

// SetLogger set the logger
func (c *BaseConfiguration) SetLogger(l *zap.Logger) {
func (c *BaseConfiguration) SetLogger(l core.Logger) {
c.Logger = l
}

Expand Down
Loading

0 comments on commit e19c417

Please sign in to comment.