Added support for Badger as an alternative storage backend

This commit is contained in:
Pijus Kamandulis
2025-03-12 21:06:10 +02:00
parent e526b2269e
commit 813b9faeaa
25 changed files with 1574 additions and 458 deletions

View File

@@ -15,6 +15,11 @@ const (
ExplorerBaseUrlLocation = "/_explorer"
)
const (
DataStoreMap = "map"
DataStoreBadger = "badger"
)
func ParseFlags() ServerConfig {
host := flag.String("Host", "localhost", "Hostname")
port := flag.Int("Port", 8081, "Listen port")
@@ -28,6 +33,8 @@ func ParseFlags() ServerConfig {
persistDataPath := flag.String("Persist", "", "Saves data to given path on application exit")
logLevel := NewEnumValue("info", []string{"debug", "info", "error", "silent"})
flag.Var(logLevel, "LogLevel", fmt.Sprintf("Sets the logging level %s", logLevel.AllowedValuesList()))
dataStore := NewEnumValue("map", []string{DataStoreMap, DataStoreBadger})
flag.Var(dataStore, "DataStore", fmt.Sprintf("Sets the data store %s, (badger is currently in the experimental phase)", dataStore.AllowedValuesList()))
flag.Parse()
setFlagsFromEnvironment()
@@ -44,6 +51,7 @@ func ParseFlags() ServerConfig {
config.DisableTls = *disableTls
config.AccountKey = *accountKey
config.LogLevel = logLevel.value
config.DataStore = dataStore.value
config.PopulateCalculatedFields()
@@ -68,6 +76,13 @@ func (c *ServerConfig) PopulateCalculatedFields() {
default:
logger.SetLogLevel(logger.LogLevelInfo)
}
if c.DataStore == DataStoreBadger &&
(c.InitialDataFilePath != "" || c.PersistDataFilePath != "") {
logger.ErrorLn("InitialData and Persist options are currently not supported with Badger data store")
c.InitialDataFilePath = ""
c.PersistDataFilePath = ""
}
}
func (c *ServerConfig) ApplyDefaultsToEmptyFields() {

View File

@@ -17,4 +17,6 @@ type ServerConfig struct {
DisableTls bool `json:"disableTls"`
LogLevel string `json:"logLevel"`
ExplorerBaseUrlLocation string `json:"explorerBaseUrlLocation"`
DataStore string `json:"dataStore"`
}