Browse Source

decouple from viper for filer store

pull/667/head
Chris Lu 7 years ago
parent
commit
eb2acd11c2
  1. 7
      weed/filer2/cassandra/cassandra_store.go
  2. 10
      weed/filer2/configuration.go
  3. 4
      weed/filer2/filerstore.go
  4. 5
      weed/filer2/leveldb/leveldb_store.go
  5. 3
      weed/filer2/memdb/memdb_store.go
  6. 17
      weed/filer2/mysql/mysql_store.go
  7. 19
      weed/filer2/postgres/postgres_store.go
  8. 9
      weed/filer2/redis/redis_store.go

7
weed/filer2/cassandra/cassandra_store.go

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

10
weed/filer2/configuration.go

@ -124,3 +124,13 @@ func (f *Filer) LoadConfiguration() {
os.Exit(-1) 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
}

4
weed/filer2/filerstore.go

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

5
weed/filer2/leveldb/leveldb_store.go

@ -7,7 +7,6 @@ import (
"github.com/chrislusf/seaweedfs/weed/filer2" "github.com/chrislusf/seaweedfs/weed/filer2"
"github.com/chrislusf/seaweedfs/weed/glog" "github.com/chrislusf/seaweedfs/weed/glog"
weed_util "github.com/chrislusf/seaweedfs/weed/util" weed_util "github.com/chrislusf/seaweedfs/weed/util"
"github.com/spf13/viper"
"github.com/syndtr/goleveldb/leveldb" "github.com/syndtr/goleveldb/leveldb"
leveldb_util "github.com/syndtr/goleveldb/leveldb/util" leveldb_util "github.com/syndtr/goleveldb/leveldb/util"
) )
@ -28,8 +27,8 @@ func (store *LevelDBStore) GetName() string {
return "leveldb" 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) return store.initialize(dir)
} }

3
weed/filer2/memdb/memdb_store.go

@ -4,7 +4,6 @@ import (
"fmt" "fmt"
"github.com/chrislusf/seaweedfs/weed/filer2" "github.com/chrislusf/seaweedfs/weed/filer2"
"github.com/google/btree" "github.com/google/btree"
"github.com/spf13/viper"
"strings" "strings"
) )
@ -28,7 +27,7 @@ func (store *MemDbStore) GetName() string {
return "memory" 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) store.tree = btree.New(8)
return nil return nil
} }

17
weed/filer2/mysql/mysql_store.go

@ -7,7 +7,6 @@ import (
"github.com/chrislusf/seaweedfs/weed/filer2" "github.com/chrislusf/seaweedfs/weed/filer2"
"github.com/chrislusf/seaweedfs/weed/filer2/abstract_sql" "github.com/chrislusf/seaweedfs/weed/filer2/abstract_sql"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"github.com/spf13/viper"
) )
const ( const (
@ -26,15 +25,15 @@ func (store *MysqlStore) GetName() string {
return "mysql" return "mysql"
} }
func (store *MysqlStore) Initialize(viper *viper.Viper) (err error) {
func (store *MysqlStore) Initialize(configuration filer2.Configuration) (err error) {
return store.initialize( 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"),
) )
} }

19
weed/filer2/postgres/postgres_store.go

@ -7,7 +7,6 @@ import (
"github.com/chrislusf/seaweedfs/weed/filer2" "github.com/chrislusf/seaweedfs/weed/filer2"
"github.com/chrislusf/seaweedfs/weed/filer2/abstract_sql" "github.com/chrislusf/seaweedfs/weed/filer2/abstract_sql"
_ "github.com/lib/pq" _ "github.com/lib/pq"
"github.com/spf13/viper"
) )
const ( const (
@ -26,16 +25,16 @@ func (store *PostgresStore) GetName() string {
return "postgres" return "postgres"
} }
func (store *PostgresStore) Initialize(viper *viper.Viper) (err error) {
func (store *PostgresStore) Initialize(configuration filer2.Configuration) (err error) {
return store.initialize( 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"),
) )
} }

9
weed/filer2/redis/redis_store.go

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

Loading…
Cancel
Save