DEVELOPMENT ENVIRONMENT

~liljamo/felu

ref: 03e1ef14c6712edfee4571e26d654a77b4cc990b felu/internal/config/config.go -rw-r--r-- 1.8 KiB
03e1ef14Jonni Liljamo chore: update Dockerfile images a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
 * 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/~skye/erya-go/util"

// FeluConfig is a global for accessing the global config.
var FeluConfig *config

type config struct {
	ServiceName string

	// API url, where the API is served at (e.g. api.feluddns.tld)
	APIUrl 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

	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"),

		APIUrl: util.LoadEnvStr("FELU_API_URL", "MUST_SET"),

		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", "."),
	}
}