feat(config): update relay list parsing

Update getRelayListFromEnvOrFile function to prioritize file over environment variable. Improve relay list parsing to handle both 'wss://' and 'ws://' prefixes.
This commit is contained in:
fsociety
2024-09-28 13:15:04 +02:00
parent a8dcf91e4c
commit b511d5455a

View File

@@ -54,15 +54,16 @@ type AwsConfig struct {
func getRelayListFromEnvOrFile(envKey, fileKey string) []string {
envValue := getEnv(envKey)
if envValue != "" {
return getRelayList(envValue)
}
filePath := getEnv(fileKey)
if filePath != "" {
return getRelayListFromFile(filePath)
}
if envValue != "" {
return getRelayList(envValue)
}
return []string{}
}
@@ -127,7 +128,13 @@ func getRelayListFromFile(filePath string) []string {
}
for i, relay := range relayList {
relayList[i] = "wss://" + strings.TrimSpace(relay)
relay = strings.TrimSpace(relay)
if strings.HasPrefix(relay, "wss://") {
relay = strings.TrimPrefix(relay, "wss://")
} else if strings.HasPrefix(relay, "ws://") {
relay = strings.TrimPrefix(relay, "ws://")
}
relayList[i] = relay
}
return relayList
}