well-goknown/config/config.go

45 lines
1.2 KiB
Go

package config
import (
"os"
)
type (
Config struct {
DbUrl string
ListenAddr string
LogLevel string
MatrixIdentityServer string
MatrixMsc3575Address string
MatrixWellKnownAddress string
RelayName string
RelayPubkey string
RelayDescription string
RelayIcon string
RelayContact string
}
)
func GetConfig() Config {
return Config{
DbUrl: getEnv("DATABASE_URL", "postgres://user:password@127.0.0.1:5432/db?sslmode=disable"),
ListenAddr: getEnv("LISTEN_ADDR", ":8090"),
LogLevel: getEnv("LOG_LEVEL", "INFO"),
MatrixIdentityServer: getEnv("MATRIX_IDENTITY_SERVER", ""),
MatrixMsc3575Address: getEnv("MATRIX_MSC3575_ADDRESS", ""),
MatrixWellKnownAddress: getEnv("MATRIX_WELL_KNOWN_ADDRESS", ""),
RelayName: getEnv("RELAY_NAME", ""),
RelayPubkey: getEnv("RELAY_PUBKEY", ""),
RelayDescription: getEnv("RELAY_DESCRIPTION", ""),
RelayIcon: getEnv("RELAY_ICON", ""),
RelayContact: getEnv("RELAY_CONTACT", ""),
}
}
func getEnv(key, fallback string) string {
if value, ok := os.LookupEnv(key); ok {
return value
}
return fallback
}