/*
* Copyright (C) 2024 Jonni Liljamo <jonni@liljamo.com>
*
* This file is licensed under AGPL-3.0-or-later, see NOTICE and LICENSE for
* more information.
*/
// Package config implements the global program config.
package config
import "git.src.quest/~liljamo/erya-go/util"
// FeluConfig is a global for accessing the global config.
var FeluConfig *config
type config struct {
ServiceName string
DDNSDomain string
SOAEmail string
// Initial email for the admin user, only used if no admin account (e.g. first boot)
InitialAdminEmail string
// Initial password for the admin user, only used if no admin account (e.g. first boot)
InitialAdminPwd string
LogLevel string
// Data directory, with trailing slash
DataDir string
FrontendBindAddr string
// API url, where the API is served at (e.g. https://api.felud.arpa)
APIUrl string
APIBindAddr string
DNSBindIP string
DNSBindPort int32
// Domain pattern, no leading dot, but with trailing dot
DNSPattern string
}
// InitConfig initializes the global program config from environment variables.
func InitConfig() {
FeluConfig = &config{
ServiceName: util.LoadEnvStr("FELU_SERVICE_NAME", "FeluDDNS"),
// FIXME: panic without this, should do same for many of these
DDNSDomain: util.LoadEnvStr("FELU_DDNS_DOMAIN", "ddns.staging.fuckdns.org"),
APIUrl: util.LoadEnvStr("FELU_API_URL", "MUST_SET"),
SOAEmail: util.LoadEnvStr("FELU_SOA_EMAIL", "admin.felu.arpa"),
InitialAdminEmail: util.LoadEnvStr("FELU_INITIAL_ADMIN_EMAIL", "admin@example.com"),
InitialAdminPwd: util.LoadEnvStr("FELU_INITIAL_ADMIN_PWD", "feluadmin"),
LogLevel: util.LoadEnvStr("FELU_LOG_LEVEL", "info"),
DataDir: util.LoadEnvStr("FELU_DB_PATH", "/var/felu/"),
FrontendBindAddr: util.LoadEnvStr("FELU_FRONTEND_BIND_ADDR", "0.0.0.0:8080"),
APIBindAddr: util.LoadEnvStr("FELU_API_BIND_ADDR", "0.0.0.0:8081"),
DNSBindIP: util.LoadEnvStr("FELU_DNS_BIND_IP", "0.0.0.0"),
DNSBindPort: util.LoadEnvInt32("FELU_DNS_BIND_PORT", 53),
DNSPattern: util.LoadEnvStr("FELU_DNS_PATTERN", "."),
}
}