33 lines
621 B
Go
Executable File
33 lines
621 B
Go
Executable File
package storage
|
|
|
|
import (
|
|
"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) {
|
|
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
|
|
|
|
}
|