Skip to content

Commit

Permalink
fix(ci): Tyk plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
darkweak committed Feb 3, 2024
1 parent 249a8da commit 9d98803
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
2 changes: 1 addition & 1 deletion plugins/traefik/override/storage/cacheProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (provider *Cache) ListKeys() []string {
return keys
}

// ListKeys method returns the list of existing keys
// MapKeys method returns the map of existing keys
func (provider *Cache) MapKeys(prefix string) map[string]string {
var keys map[string]string
provider.Cache.Range(func(key, value interface{}) bool {
Expand Down
21 changes: 6 additions & 15 deletions plugins/tyk/override/storage/abstractProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"net/http"
"net/url"
"strings"
"time"

"github.com/darkweak/souin/configurationtypes"
"github.com/darkweak/souin/pkg/rfc"
Expand All @@ -17,23 +16,15 @@ const (
StalePrefix = "STALE_"
)

type Storer interface {
ListKeys() []string
Prefix(key string, req *http.Request, validator *rfc.Revalidator) *http.Response
Get(key string) []byte
Set(key string, value []byte, url configurationtypes.URL, duration time.Duration) error
Delete(key string)
DeleteMany(key string)
Init() error
Name() string
Reset() error
}

type StorerInstanciator func(configurationtypes.AbstractConfigurationInterface) (types.Storer, error)

func NewStorages(configuration configurationtypes.AbstractConfigurationInterface) ([]Storer, error) {
func NewStorageFromName(_ string) (StorerInstanciator, error) {
return CacheConnectionFactory, nil
}

func NewStorages(configuration configurationtypes.AbstractConfigurationInterface) ([]types.Storer, error) {
s, err := CacheConnectionFactory(configuration)
return []Storer{s}, err
return []types.Storer{s}, err
}

func varyVoter(baseKey string, req *http.Request, currentKey string) bool {
Expand Down
11 changes: 11 additions & 0 deletions plugins/tyk/override/storage/cacheProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ func (provider *Cache) ListKeys() []string {
return keys
}

// MapKeys method returns the map of existing keys
func (provider *Cache) MapKeys(prefix string) map[string]string {
var keys map[string]string
items := provider.Items()
for k, v := range items {
keys[k] = v.Object.(string)
}

return keys
}

// Get method returns the populated response if exists, empty response then
func (provider *Cache) Get(key string) []byte {
result, found := provider.Cache.Get(key)
Expand Down
22 changes: 22 additions & 0 deletions plugins/tyk/override/storage/types/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package types

import (
"net/http"
"time"

"github.com/darkweak/souin/configurationtypes"
"github.com/darkweak/souin/pkg/rfc"
)

type Storer interface {
MapKeys(prefix string) map[string]string
ListKeys() []string
Prefix(key string, req *http.Request, validator *rfc.Revalidator) *http.Response
Get(key string) []byte
Set(key string, value []byte, url configurationtypes.URL, duration time.Duration) error
Delete(key string)
DeleteMany(key string)
Init() error
Name() string
Reset() error
}

0 comments on commit 9d98803

Please sign in to comment.