parcoursmob/utils/storage/kv.go

33 lines
621 B
Go
Raw Permalink Normal View History

package storage
import (
2023-05-19 08:06:30 +00:00
"fmt"
"time"
"github.com/spf13/viper"
)
type KVHandler interface {
Put(k string, v any) error
PutWithTTL(k string, v any, duration time.Duration) error
Get(k string) (any, error)
Delete(k string) error
}
func NewKVHandler(cfg *viper.Viper) (KVHandler, error) {
2023-05-19 08:06:30 +00:00
cacheType := cfg.GetString("storage.kv.dbType")
switch cacheType {
case "etcd":
return NewEtcdHandler(cfg)
case "badger":
return NewBadgerHandler(cfg)
case "etcdGroupcache":
return NewGroupCacheHandler(cfg)
fmt.Println("here")
case "badgerGroupcache":
return NewGroupCacheHandler(cfg)
}
return nil, nil
}