feat: Use databaseBackend config repace databaseEtcd

databaseBackend config contains type and url sub config, It can facilitate the expansion of other types of databases in the future.
This commit is contained in:
hudeng authored and André Roth committed 2024-07-31 22:16:00 +02:00
1 parent f29449db14
commit 59bf4501e8
8 files changed
+47 -13

No files matched your search

+10 -2
View File
@@ -3,6 +3,7 @@ package context
import (
gocontext "context"
"errors"
"fmt"
"math/rand"
"os"
@@ -289,8 +290,15 @@ func (context *AptlyContext) _database() (database.Storage, error) {
if context.database == nil {
var err error
if context.config().DatabaseEtcd != "" {
context.database, err = etcddb.NewDB(context.config().DatabaseEtcd)
if context.config().DatabaseBackend.Type == "etcd" {
context.database, err = etcddb.NewDB(context.config().DatabaseBackend.URL)
} else if context.config().DatabaseBackend.Type == "leveldb" {
if context.config().DatabaseBackend.DbPath != "" {
dbPath := filepath.Join(context.config().RootDir, context.config().DatabaseBackend.DbPath)
context.database, err = goleveldb.NewDB(dbPath)
} else {
return nil, errors.New("leveldb databaseBackend config invalid")
}
} else {
context.database, err = goleveldb.NewDB(context.dbPath())
}