traefik/pkg/provider/kv/storewrapper.go

121 lines
2.9 KiB
Go
Raw Permalink Normal View History

package kv
import (
2022-08-11 13:42:07 +00:00
"context"
"github.com/kvtools/valkeyrie/store"
2022-11-21 17:36:05 +00:00
"github.com/rs/zerolog/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 {
2022-11-21 17:36:05 +00:00
log.Debug().Msgf("Put: %s %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) {
2022-11-21 17:36:05 +00:00
log.Debug().Msgf("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 {
2022-11-21 17:36:05 +00:00
log.Debug().Msgf("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) {
2022-11-21 17:36:05 +00:00
log.Debug().Msgf("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) {
2022-11-21 17:36:05 +00:00
log.Debug().Msgf("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) {
2022-11-21 17:36:05 +00:00
log.Debug().Msgf("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) {
2022-11-21 17:36:05 +00:00
log.Debug().Msgf("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) {
2022-11-21 17:36:05 +00:00
log.Debug().Msgf("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 {
2022-11-21 17:36:05 +00:00
log.Debug().Msgf("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) {
2022-11-21 17:36:05 +00:00
log.Debug().Msgf("AtomicPut: %s %s %v", 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) {
2022-11-21 17:36:05 +00:00
log.Debug().Msgf("AtomicDelete: %s %v", 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 {
2022-11-21 17:36:05 +00:00
log.Debug().Msg("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()
}