mirror of
https://github.com/aljazceru/haven.git
synced 2026-02-02 20:24:21 +01:00
feat: add support for relay list from json file
This commit adds the ability to specify relay lists in a json file for both import and blastr settings. This provides more flexibility in configuring the application. It also includes error handling for reading and parsing the json file.
This commit is contained in:
@@ -32,6 +32,7 @@ INBOX_PULL_INTERVAL_SECONDS=600
|
||||
IMPORT_START_DATE="2023-01-20"
|
||||
IMPORT_QUERY_INTERVAL_SECONDS=600
|
||||
IMPORT_SEED_RELAYS="relay.damus.io,nos.lol,relay.nostr.band,relay.snort.social,nostr.land,nostr.mom,relay.nos.social,relay.primal.net,relay.nostr.bg,no.str.cr,nostr21.com,nostrue.com,relay.siamstr.com,wot.utxo.one,nostrelites.org,wot.nostr.party,wot.sovbit.host,wot.girino.org,relay.lnau.net,wot.siamstr.com,wot.sudocarlos.com,relay.otherstuff.fyi,relay.lexingtonbitcoin.org,wot.azzamo.net,wot.swarmstr.com,zap.watch,satsage.xyz,wons.calva.dev"
|
||||
IMPORT_SEED_RELAYS_FILE="" # If you want to use a json file, set this to the path of the file (e.g. "relays_import.json")
|
||||
|
||||
## Backup Settings
|
||||
BACKUP_PROVIDER="aws"
|
||||
@@ -45,6 +46,7 @@ AWS_BUCKET_NAME="utxo-relay-backups"
|
||||
|
||||
## Blastr Settings
|
||||
BLASTR_RELAYS="relay.damus.io,nos.lol,relay.nostr.band,relay.snort.social,nostr.land,nostr.mom,relay.nos.social,relay.primal.net,relay.nostr.bg,no.str.cr,nostr21.com,nostrue.com,relay.siamstr.com,wot.utxo.one,nostrelites.org,wot.nostr.party,wot.sovbit.host,wot.girino.org,relay.lnau.net,wot.siamstr.com,wot.sudocarlos.com,relay.otherstuff.fyi,relay.lexingtonbitcoin.org,wot.azzamo.net,wot.swarmstr.com,zap.watch,satsage.xyz,wons.calva.dev"
|
||||
BLASTR_RELAYS_FILE="" # If you want to use a json file, set this to the path of the file (e.g. "relays_blastr.json")
|
||||
|
||||
## OPTIONAL: Docker UID and GID - should be the same as the user running the docker container
|
||||
DOCKER_UID=1000
|
||||
|
||||
37
config.go
37
config.go
@@ -5,6 +5,8 @@ import (
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
@@ -48,6 +50,20 @@ type AwsConfig struct {
|
||||
Bucket string `json:"bucket"`
|
||||
}
|
||||
|
||||
func getRelayListFromEnvOrFile(envKey, fileKey string) []string {
|
||||
envValue := getEnv(envKey)
|
||||
if envValue != "" {
|
||||
return getRelayList(envValue)
|
||||
}
|
||||
|
||||
filePath := getEnv(fileKey)
|
||||
if filePath != "" {
|
||||
return getRelayListFromFile(filePath)
|
||||
}
|
||||
|
||||
return []string{}
|
||||
}
|
||||
|
||||
func loadConfig() Config {
|
||||
godotenv.Load(".env")
|
||||
|
||||
@@ -77,10 +93,10 @@ func loadConfig() Config {
|
||||
InboxPullIntervalSeconds: getEnvInt("INBOX_PULL_INTERVAL_SECONDS", 3600),
|
||||
ImportStartDate: getEnv("IMPORT_START_DATE"),
|
||||
ImportQueryIntervalSeconds: getEnvInt("IMPORT_QUERY_INTERVAL_SECONDS", 360000),
|
||||
ImportSeedRelays: getRelayList(getEnv("IMPORT_SEED_RELAYS")),
|
||||
ImportSeedRelays: getRelayListFromEnvOrFile("IMPORT_SEED_RELAYS", "IMPORT_SEED_RELAYS_FILE"),
|
||||
BackupProvider: getEnv("BACKUP_PROVIDER"),
|
||||
BackupIntervalHours: getEnvInt("BACKUP_INTERVAL_HOURS", 24),
|
||||
BlastrRelays: getRelayList(getEnv("BLASTR_RELAYS")),
|
||||
BlastrRelays: getRelayListFromEnvOrFile("BLASTR_RELAYS", "BLASTR_RELAYS_FILE"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,6 +108,23 @@ func getRelayList(commaList string) []string {
|
||||
return relayList
|
||||
}
|
||||
|
||||
func getRelayListFromFile(filePath string) []string {
|
||||
file, err := ioutil.ReadFile(filePath)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to read file: %s", err)
|
||||
}
|
||||
|
||||
var relayList []string
|
||||
if err := json.Unmarshal(file, &relayList); err != nil {
|
||||
log.Fatalf("Failed to parse JSON: %s", err)
|
||||
}
|
||||
|
||||
for i, relay := range relayList {
|
||||
relayList[i] = "wss://" + strings.TrimSpace(relay)
|
||||
}
|
||||
return relayList
|
||||
}
|
||||
|
||||
func getEnv(key string) string {
|
||||
value, exists := os.LookupEnv(key)
|
||||
if !exists {
|
||||
|
||||
30
relays_blastr.json
Normal file
30
relays_blastr.json
Normal file
@@ -0,0 +1,30 @@
|
||||
[
|
||||
"relay.damus.io",
|
||||
"nos.lol",
|
||||
"relay.nostr.band",
|
||||
"relay.snort.social",
|
||||
"nostr.land",
|
||||
"nostr.mom",
|
||||
"relay.nos.social",
|
||||
"relay.primal.net",
|
||||
"relay.nostr.bg",
|
||||
"no.str.cr",
|
||||
"nostr21.com",
|
||||
"nostrue.com",
|
||||
"relay.siamstr.com",
|
||||
"wot.utxo.one",
|
||||
"nostrelites.org",
|
||||
"wot.nostr.party",
|
||||
"wot.sovbit.host",
|
||||
"wot.girino.org",
|
||||
"relay.lnau.net",
|
||||
"wot.siamstr.com",
|
||||
"wot.sudocarlos.com",
|
||||
"relay.otherstuff.fyi",
|
||||
"relay.lexingtonbitcoin.org",
|
||||
"wot.azzamo.net",
|
||||
"wot.swarmstr.com",
|
||||
"zap.watch",
|
||||
"satsage.xyz",
|
||||
"wons.calva.dev"
|
||||
]
|
||||
30
relays_import.json
Normal file
30
relays_import.json
Normal file
@@ -0,0 +1,30 @@
|
||||
[
|
||||
"relay.damus.io",
|
||||
"nos.lol",
|
||||
"relay.nostr.band",
|
||||
"relay.snort.social",
|
||||
"nostr.land",
|
||||
"nostr.mom",
|
||||
"relay.nos.social",
|
||||
"relay.primal.net",
|
||||
"relay.nostr.bg",
|
||||
"no.str.cr",
|
||||
"nostr21.com",
|
||||
"nostrue.com",
|
||||
"relay.siamstr.com",
|
||||
"wot.utxo.one",
|
||||
"nostrelites.org",
|
||||
"wot.nostr.party",
|
||||
"wot.sovbit.host",
|
||||
"wot.girino.org",
|
||||
"relay.lnau.net",
|
||||
"wot.siamstr.com",
|
||||
"wot.sudocarlos.com",
|
||||
"relay.otherstuff.fyi",
|
||||
"relay.lexingtonbitcoin.org",
|
||||
"wot.azzamo.net",
|
||||
"wot.swarmstr.com",
|
||||
"zap.watch",
|
||||
"satsage.xyz",
|
||||
"wons.calva.dev"
|
||||
]
|
||||
Reference in New Issue
Block a user