well-goknown/config/config.go

45 lines
1.2 KiB
Go
Raw Normal View History

2023-02-05 01:21:10 +00:00
package config
import (
"os"
)
type (
Config struct {
2024-08-10 23:55:16 +00:00
DbUrl string
2023-04-29 18:01:40 +00:00
ListenAddr string
LogLevel string
2023-02-05 01:21:10 +00:00
MatrixIdentityServer string
2024-02-12 02:27:05 +00:00
MatrixMsc3575Address string
2024-08-10 23:55:16 +00:00
MatrixWellKnownAddress string
2024-08-15 01:20:14 +00:00
RelayName string
RelayPubkey string
RelayDescription string
RelayIcon string
RelayContact string
2023-02-05 01:21:10 +00:00
}
)
func GetConfig() Config {
return Config{
2024-08-10 23:55:16 +00:00
DbUrl: getEnv("DATABASE_URL", "postgres://user:password@127.0.0.1:5432/db?sslmode=disable"),
2023-04-29 18:01:40 +00:00
ListenAddr: getEnv("LISTEN_ADDR", ":8090"),
LogLevel: getEnv("LOG_LEVEL", "INFO"),
2023-02-05 01:21:10 +00:00
MatrixIdentityServer: getEnv("MATRIX_IDENTITY_SERVER", ""),
2024-02-12 02:27:05 +00:00
MatrixMsc3575Address: getEnv("MATRIX_MSC3575_ADDRESS", ""),
2024-08-10 23:55:16 +00:00
MatrixWellKnownAddress: getEnv("MATRIX_WELL_KNOWN_ADDRESS", ""),
2024-08-15 01:20:14 +00:00
RelayName: getEnv("RELAY_NAME", ""),
RelayPubkey: getEnv("RELAY_PUBKEY", ""),
RelayDescription: getEnv("RELAY_DESCRIPTION", ""),
RelayIcon: getEnv("RELAY_ICON", ""),
RelayContact: getEnv("RELAY_CONTACT", ""),
2023-02-05 01:21:10 +00:00
}
}
func getEnv(key, fallback string) string {
if value, ok := os.LookupEnv(key); ok {
return value
}
return fallback
}