decouple from viper for filer store

This commit is contained in:
Chris Lu 2018-06-17 13:01:57 -07:00
parent 0467195f07
commit eb2acd11c2
8 changed files with 39 additions and 35 deletions

View file

@ -5,7 +5,6 @@ import (
"github.com/chrislusf/seaweedfs/weed/filer2"
"github.com/chrislusf/seaweedfs/weed/glog"
"github.com/gocql/gocql"
"github.com/spf13/viper"
)
func init() {
@ -21,10 +20,10 @@ func (store *CassandraStore) GetName() string {
return "cassandra"
}
func (store *CassandraStore) Initialize(viper *viper.Viper) (err error) {
func (store *CassandraStore) Initialize(configuration filer2.Configuration) (err error) {
return store.initialize(
viper.GetString("keyspace"),
viper.GetStringSlice("hosts"),
configuration.GetString("keyspace"),
configuration.GetStringSlice("hosts"),
)
}

View file

@ -124,3 +124,13 @@ func (f *Filer) LoadConfiguration() {
os.Exit(-1)
}
// A simplified interface to decouple from Viper
type Configuration interface {
GetString(key string) string
GetBool(key string) bool
GetInt(key string) int
GetInt64(key string) int64
GetFloat64(key string) float64
GetStringSlice(key string) []string
}

View file

@ -2,12 +2,12 @@ package filer2
import (
"errors"
"github.com/spf13/viper"
)
type FilerStore interface {
GetName() string
Initialize(viper *viper.Viper) error
// Initialize initializes the file store
Initialize(configuration Configuration) error
InsertEntry(*Entry) error
UpdateEntry(*Entry) (err error)
FindEntry(FullPath) (entry *Entry, err error)

View file

@ -7,7 +7,6 @@ import (
"github.com/chrislusf/seaweedfs/weed/filer2"
"github.com/chrislusf/seaweedfs/weed/glog"
weed_util "github.com/chrislusf/seaweedfs/weed/util"
"github.com/spf13/viper"
"github.com/syndtr/goleveldb/leveldb"
leveldb_util "github.com/syndtr/goleveldb/leveldb/util"
)
@ -28,8 +27,8 @@ func (store *LevelDBStore) GetName() string {
return "leveldb"
}
func (store *LevelDBStore) Initialize(viper *viper.Viper) (err error) {
dir := viper.GetString("dir")
func (store *LevelDBStore) Initialize(configuration filer2.Configuration) (err error) {
dir := configuration.GetString("dir")
return store.initialize(dir)
}

View file

@ -4,7 +4,6 @@ import (
"fmt"
"github.com/chrislusf/seaweedfs/weed/filer2"
"github.com/google/btree"
"github.com/spf13/viper"
"strings"
)
@ -28,7 +27,7 @@ func (store *MemDbStore) GetName() string {
return "memory"
}
func (store *MemDbStore) Initialize(viper *viper.Viper) (err error) {
func (store *MemDbStore) Initialize(configuration filer2.Configuration) (err error) {
store.tree = btree.New(8)
return nil
}

View file

@ -7,7 +7,6 @@ import (
"github.com/chrislusf/seaweedfs/weed/filer2"
"github.com/chrislusf/seaweedfs/weed/filer2/abstract_sql"
_ "github.com/go-sql-driver/mysql"
"github.com/spf13/viper"
)
const (
@ -26,15 +25,15 @@ func (store *MysqlStore) GetName() string {
return "mysql"
}
func (store *MysqlStore) Initialize(viper *viper.Viper) (err error) {
func (store *MysqlStore) Initialize(configuration filer2.Configuration) (err error) {
return store.initialize(
viper.GetString("username"),
viper.GetString("password"),
viper.GetString("hostname"),
viper.GetInt("port"),
viper.GetString("database"),
viper.GetInt("connection_max_idle"),
viper.GetInt("connection_max_open"),
configuration.GetString("username"),
configuration.GetString("password"),
configuration.GetString("hostname"),
configuration.GetInt("port"),
configuration.GetString("database"),
configuration.GetInt("connection_max_idle"),
configuration.GetInt("connection_max_open"),
)
}

View file

@ -7,7 +7,6 @@ import (
"github.com/chrislusf/seaweedfs/weed/filer2"
"github.com/chrislusf/seaweedfs/weed/filer2/abstract_sql"
_ "github.com/lib/pq"
"github.com/spf13/viper"
)
const (
@ -26,16 +25,16 @@ func (store *PostgresStore) GetName() string {
return "postgres"
}
func (store *PostgresStore) Initialize(viper *viper.Viper) (err error) {
func (store *PostgresStore) Initialize(configuration filer2.Configuration) (err error) {
return store.initialize(
viper.GetString("username"),
viper.GetString("password"),
viper.GetString("hostname"),
viper.GetInt("port"),
viper.GetString("database"),
viper.GetString("sslmode"),
viper.GetInt("connection_max_idle"),
viper.GetInt("connection_max_open"),
configuration.GetString("username"),
configuration.GetString("password"),
configuration.GetString("hostname"),
configuration.GetInt("port"),
configuration.GetString("database"),
configuration.GetString("sslmode"),
configuration.GetInt("connection_max_idle"),
configuration.GetInt("connection_max_open"),
)
}

View file

@ -5,7 +5,6 @@ import (
"github.com/chrislusf/seaweedfs/weed/filer2"
"github.com/chrislusf/seaweedfs/weed/glog"
"github.com/go-redis/redis"
"github.com/spf13/viper"
"sort"
"strings"
)
@ -26,11 +25,11 @@ func (store *RedisStore) GetName() string {
return "redis"
}
func (store *RedisStore) Initialize(viper *viper.Viper) (err error) {
func (store *RedisStore) Initialize(configuration filer2.Configuration) (err error) {
return store.initialize(
viper.GetString("address"),
viper.GetString("password"),
viper.GetInt("database"),
configuration.GetString("address"),
configuration.GetString("password"),
configuration.GetInt("database"),
)
}