mirror of
https://github.com/aljazceru/haven.git
synced 2025-12-18 22:24:22 +01:00
Add support for configurable binding address
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
OWNER_NPUB="npub1utx00neqgqln72j22kej3ux7803c2k986henvvha4thuwfkper4s7r50e8"
|
OWNER_NPUB="npub1utx00neqgqln72j22kej3ux7803c2k986henvvha4thuwfkper4s7r50e8"
|
||||||
RELAY_URL="relay.utxo.one"
|
RELAY_URL="relay.utxo.one"
|
||||||
|
RELAY_PORT=3355
|
||||||
|
RELAY_BIND_ADDRESS="0.0.0.0" # Can be set to a specific IP4 or IP6 address ("" for all interfaces)
|
||||||
DB_ENGINE="badger" # badger, lmdb (lmdb works best with an nvme, otherwise you might have stability issues)
|
DB_ENGINE="badger" # badger, lmdb (lmdb works best with an nvme, otherwise you might have stability issues)
|
||||||
|
|
||||||
## Private Relay Settings
|
## Private Relay Settings
|
||||||
|
|||||||
18
config.go
18
config.go
@@ -14,6 +14,8 @@ type Config struct {
|
|||||||
OwnerNpub string `json:"owner_npub"`
|
OwnerNpub string `json:"owner_npub"`
|
||||||
DBEngine string `json:"db_engine"`
|
DBEngine string `json:"db_engine"`
|
||||||
RelayURL string `json:"relay_url"`
|
RelayURL string `json:"relay_url"`
|
||||||
|
RelayPort int `json:"relay_port"`
|
||||||
|
RelayBindAddress string `json:"relay_bind_address"`
|
||||||
RelaySoftware string `json:"relay_software"`
|
RelaySoftware string `json:"relay_software"`
|
||||||
RelayVersion string `json:"relay_version"`
|
RelayVersion string `json:"relay_version"`
|
||||||
PrivateRelayName string `json:"private_relay_name"`
|
PrivateRelayName string `json:"private_relay_name"`
|
||||||
@@ -52,15 +54,14 @@ type AwsConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func loadConfig() Config {
|
func loadConfig() Config {
|
||||||
godotenv.Load(".env")
|
_ = godotenv.Load(".env")
|
||||||
if os.Getenv("DB_ENGINE") == "" {
|
|
||||||
os.Setenv("DB_ENGINE", "lmdb")
|
|
||||||
}
|
|
||||||
|
|
||||||
return Config{
|
return Config{
|
||||||
OwnerNpub: getEnv("OWNER_NPUB"),
|
OwnerNpub: getEnv("OWNER_NPUB"),
|
||||||
DBEngine: getEnv("DB_ENGINE"),
|
DBEngine: getEnvString("DB_ENGINE", "lmdb"),
|
||||||
RelayURL: getEnv("RELAY_URL"),
|
RelayURL: getEnv("RELAY_URL"),
|
||||||
|
RelayPort: getEnvInt("RELAY_PORT", 3355),
|
||||||
|
RelayBindAddress: getEnvString("RELAY_BIND_ADDRESS", "0.0.0.0"),
|
||||||
RelaySoftware: "https://github.com/bitvora/haven",
|
RelaySoftware: "https://github.com/bitvora/haven",
|
||||||
RelayVersion: "v0.4.4",
|
RelayVersion: "v0.4.4",
|
||||||
PrivateRelayName: getEnv("PRIVATE_RELAY_NAME"),
|
PrivateRelayName: getEnv("PRIVATE_RELAY_NAME"),
|
||||||
@@ -121,6 +122,13 @@ func getEnv(key string) string {
|
|||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getEnvString(key string, defaultValue string) string {
|
||||||
|
if value, ok := os.LookupEnv(key); ok {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
return defaultValue
|
||||||
|
}
|
||||||
|
|
||||||
func getEnvInt(key string, defaultValue int) int {
|
func getEnvInt(key string, defaultValue int) int {
|
||||||
if value, ok := os.LookupEnv(key); ok {
|
if value, ok := os.LookupEnv(key); ok {
|
||||||
intValue, err := strconv.Atoi(value)
|
intValue, err := strconv.Atoi(value)
|
||||||
|
|||||||
6
main.go
6
main.go
@@ -48,8 +48,10 @@ func main() {
|
|||||||
|
|
||||||
http.HandleFunc("/", dynamicRelayHandler)
|
http.HandleFunc("/", dynamicRelayHandler)
|
||||||
|
|
||||||
log.Printf("🔗 listening at http://localhost:3355")
|
addr := fmt.Sprintf("%s:%d", config.RelayBindAddress, config.RelayPort)
|
||||||
http.ListenAndServe("0.0.0.0:3355", nil)
|
|
||||||
|
log.Printf("🔗 listening at %s", addr)
|
||||||
|
http.ListenAndServe(addr, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func dynamicRelayHandler(w http.ResponseWriter, r *http.Request) {
|
func dynamicRelayHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
Reference in New Issue
Block a user