traefik/pkg/provider/kv/storewrapper.go

121 lines
3.1 KiB
Go
Raw Normal View History

package kv
import (
2022-08-11 13:42:07 +00:00
"context"
"github.com/kvtools/valkeyrie/store"
"github.com/traefik/traefik/v2/pkg/log"
)
type storeWrapper struct {
store.Store
}
2022-08-11 13:42:07 +00:00
func (s *storeWrapper) Put(ctx context.Context, key string, value []byte, options *store.WriteOptions) error {
log.WithoutContext().Debugf("Put: %s", key, string(value))
if s.Store == nil {
return nil
}
2022-08-11 13:42:07 +00:00
return s.Store.Put(ctx, key, value, options)
}
2022-08-11 13:42:07 +00:00
func (s *storeWrapper) Get(ctx context.Context, key string, options *store.ReadOptions) (*store.KVPair, error) {
log.WithoutContext().Debugf("Get: %s", key)
if s.Store == nil {
return nil, nil
}
2022-08-11 13:42:07 +00:00
return s.Store.Get(ctx, key, options)
}
2022-08-11 13:42:07 +00:00
func (s *storeWrapper) Delete(ctx context.Context, key string) error {
log.WithoutContext().Debugf("Delete: %s", key)
if s.Store == nil {
return nil
}
2022-08-11 13:42:07 +00:00
return s.Store.Delete(ctx, key)
}
2022-08-11 13:42:07 +00:00
func (s *storeWrapper) Exists(ctx context.Context, key string, options *store.ReadOptions) (bool, error) {
log.WithoutContext().Debugf("Exists: %s", key)
if s.Store == nil {
return true, nil
}
2022-08-11 13:42:07 +00:00
return s.Store.Exists(ctx, key, options)
}
2022-08-11 13:42:07 +00:00
func (s *storeWrapper) Watch(ctx context.Context, key string, options *store.ReadOptions) (<-chan *store.KVPair, error) {
log.WithoutContext().Debugf("Watch: %s", key)
if s.Store == nil {
return nil, nil
}
2022-08-11 13:42:07 +00:00
return s.Store.Watch(ctx, key, options)
}
2022-08-11 13:42:07 +00:00
func (s *storeWrapper) WatchTree(ctx context.Context, directory string, options *store.ReadOptions) (<-chan []*store.KVPair, error) {
log.WithoutContext().Debugf("WatchTree: %s", directory)
if s.Store == nil {
return nil, nil
}
2022-08-11 13:42:07 +00:00
return s.Store.WatchTree(ctx, directory, options)
}
2022-08-11 13:42:07 +00:00
func (s *storeWrapper) NewLock(ctx context.Context, key string, options *store.LockOptions) (store.Locker, error) {
log.WithoutContext().Debugf("NewLock: %s", key)
if s.Store == nil {
return nil, nil
}
2022-08-11 13:42:07 +00:00
return s.Store.NewLock(ctx, key, options)
}
2022-08-11 13:42:07 +00:00
func (s *storeWrapper) List(ctx context.Context, directory string, options *store.ReadOptions) ([]*store.KVPair, error) {
log.WithoutContext().Debugf("List: %s", directory)
if s.Store == nil {
return nil, nil
}
2022-08-11 13:42:07 +00:00
return s.Store.List(ctx, directory, options)
}
2022-08-11 13:42:07 +00:00
func (s *storeWrapper) DeleteTree(ctx context.Context, directory string) error {
log.WithoutContext().Debugf("DeleteTree: %s", directory)
if s.Store == nil {
return nil
}
2022-08-11 13:42:07 +00:00
return s.Store.DeleteTree(ctx, directory)
}
2022-08-11 13:42:07 +00:00
func (s *storeWrapper) AtomicPut(ctx context.Context, key string, value []byte, previous *store.KVPair, options *store.WriteOptions) (bool, *store.KVPair, error) {
log.WithoutContext().Debugf("AtomicPut: %s", key, string(value), previous)
if s.Store == nil {
return true, nil, nil
}
2022-08-11 13:42:07 +00:00
return s.Store.AtomicPut(ctx, key, value, previous, options)
}
2022-08-11 13:42:07 +00:00
func (s *storeWrapper) AtomicDelete(ctx context.Context, key string, previous *store.KVPair) (bool, error) {
log.WithoutContext().Debugf("AtomicDelete: %s", key, previous)
if s.Store == nil {
return true, nil
}
2022-08-11 13:42:07 +00:00
return s.Store.AtomicDelete(ctx, key, previous)
}
2022-08-11 13:42:07 +00:00
func (s *storeWrapper) Close() error {
log.WithoutContext().Debugf("Close")
if s.Store == nil {
2022-08-11 13:42:07 +00:00
return nil
}
2022-08-11 13:42:07 +00:00
return s.Store.Close()
}