Skip to content

Commit

Permalink
Implement db directory env (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
pablomendezroyo authored Dec 10, 2024
1 parent 3c6fff7 commit 2043cdc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func main() {
logger.DebugWithPrefix(logPrefix, "Network config: %+v", networkConfig)

// Initialize adapters
storageAdapter := storage.NewStorageAdapter()
storageAdapter := storage.NewStorageAdapter(networkConfig.DBDirectory)
notifierAdapter, err := notifier.NewNotifierAdapter(ctx, storageAdapter)
if err != nil {
logger.WarnWithPrefix(logPrefix, "Telegram notifier not initialized: %v", err)
Expand Down
5 changes: 3 additions & 2 deletions internal/adapters/storage/storage_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"lido-events/internal/application/domain"
"math/big"
"os"
"strings"
"sync"
)

Expand All @@ -17,9 +18,9 @@ type Storage struct {
telegramConfigListeners []chan domain.TelegramConfig
}

func NewStorageAdapter() *Storage {
func NewStorageAdapter(dbDirectory string) *Storage {
return &Storage{
DBFile: "db.json",
DBFile: fmt.Sprintf("%s/db.json", strings.TrimRight(dbDirectory, "/")),
}
}

Expand Down
12 changes: 12 additions & 0 deletions internal/config/config_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

type Config struct {
DBDirectory string
MevBoostDnpName string
DappmanagerUrl string
SignerUrl string
Expand Down Expand Up @@ -68,6 +69,15 @@ func LoadNetworkConfig() (Config, error) {
dappmanagerUrl = "http://my.dappnode"
}

dbDirectory := os.Getenv("DB_PATH")
if dbDirectory == "" {
cwd, err := os.Getwd()
if err != nil {
logger.Fatal("Failed to get working directory: %v", err)
}
dbDirectory = cwd
}

apiPortStr := os.Getenv("API_PORT")
apiPort := uint64(8080)
if apiPortStr != "" {
Expand Down Expand Up @@ -127,6 +137,7 @@ func LoadNetworkConfig() (Config, error) {
beaconchainURL = "http://beacon-chain.holesky.dncore.dappnode:3500"
}
config = Config{
DBDirectory: dbDirectory,
MevBoostDnpName: "mev-boost-holesky.dnp.dappnode.eth",
DappmanagerUrl: dappmanagerUrl,
SignerUrl: "http://signer.holesky.dncore.dappnode:9000",
Expand Down Expand Up @@ -162,6 +173,7 @@ func LoadNetworkConfig() (Config, error) {
beaconchainURL = "http://beacon-chain.mainnet.dncore.dappnode:3500"
}
config = Config{
DBDirectory: dbDirectory,
MevBoostDnpName: "mev-boost.dnp.dappnode.eth",
DappmanagerUrl: dappmanagerUrl,
SignerUrl: "http://signer.mainnet.dncore.dappnode:9000",
Expand Down

0 comments on commit 2043cdc

Please sign in to comment.