2024-05-03 17:11:56 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2024-05-13 11:40:01 +00:00
|
|
|
"log/slog"
|
2024-05-03 17:11:56 +00:00
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
2024-07-03 20:45:37 +00:00
|
|
|
var Version string
|
|
|
|
|
2024-05-03 17:11:56 +00:00
|
|
|
type App struct {
|
2024-05-13 11:40:01 +00:00
|
|
|
// general config
|
|
|
|
LogLevel string
|
2024-05-22 20:57:29 +00:00
|
|
|
|
2024-05-04 15:36:57 +00:00
|
|
|
// configuration for server
|
2024-05-03 17:11:56 +00:00
|
|
|
Prefork bool
|
|
|
|
Host string
|
|
|
|
Port int
|
|
|
|
ProxyHeader string
|
|
|
|
AllowOrigin string
|
2024-05-22 20:57:29 +00:00
|
|
|
|
2024-05-04 15:36:57 +00:00
|
|
|
// configuration for prober (client)
|
|
|
|
ServerEndpoint string
|
2024-06-19 09:24:18 +00:00
|
|
|
APIKey string
|
2024-05-04 15:36:57 +00:00
|
|
|
AcceptTor bool
|
2024-06-19 09:24:18 +00:00
|
|
|
TorSOCKS string
|
2024-09-05 17:08:59 +00:00
|
|
|
IPv6Capable bool
|
2024-05-03 17:11:56 +00:00
|
|
|
}
|
|
|
|
|
2024-07-03 20:45:37 +00:00
|
|
|
func init() {
|
|
|
|
if Version == "" {
|
|
|
|
Version = "v0.0.0-alpha.0.000000.dev"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-03 17:11:56 +00:00
|
|
|
var app = &App{}
|
|
|
|
|
|
|
|
func AppCfg() *App {
|
|
|
|
return app
|
|
|
|
}
|
|
|
|
|
2024-05-04 15:36:57 +00:00
|
|
|
// loads App configuration
|
2024-05-03 17:11:56 +00:00
|
|
|
func LoadApp() {
|
2024-05-13 11:40:01 +00:00
|
|
|
// general config
|
|
|
|
app.LogLevel = os.Getenv("LOG_LEVEL")
|
|
|
|
switch app.LogLevel {
|
|
|
|
case "DEBUG":
|
|
|
|
slog.SetLogLoggerLevel(slog.LevelDebug)
|
|
|
|
case "ERROR":
|
|
|
|
slog.SetLogLoggerLevel(slog.LevelError)
|
|
|
|
case "WARN":
|
|
|
|
slog.SetLogLoggerLevel(slog.LevelWarn)
|
|
|
|
default:
|
|
|
|
slog.SetLogLoggerLevel(slog.LevelInfo)
|
|
|
|
}
|
|
|
|
|
2024-05-04 15:36:57 +00:00
|
|
|
// server configuration
|
2024-05-03 17:11:56 +00:00
|
|
|
app.Host = os.Getenv("APP_HOST")
|
|
|
|
app.Port, _ = strconv.Atoi(os.Getenv("APP_PORT"))
|
|
|
|
app.Prefork, _ = strconv.ParseBool(os.Getenv("APP_PREFORK"))
|
|
|
|
app.ProxyHeader = os.Getenv("APP_PROXY_HEADER")
|
|
|
|
app.AllowOrigin = os.Getenv("APP_ALLOW_ORIGIN")
|
2024-05-13 11:40:01 +00:00
|
|
|
|
2024-05-04 15:36:57 +00:00
|
|
|
// prober configuration
|
|
|
|
app.ServerEndpoint = os.Getenv("SERVER_ENDPOINT")
|
2024-06-19 09:24:18 +00:00
|
|
|
app.APIKey = os.Getenv("API_KEY")
|
2024-05-04 15:36:57 +00:00
|
|
|
app.AcceptTor, _ = strconv.ParseBool(os.Getenv("ACCEPT_TOR"))
|
2024-06-19 09:24:18 +00:00
|
|
|
app.TorSOCKS = os.Getenv("TOR_SOCKS")
|
2024-09-05 17:08:59 +00:00
|
|
|
app.IPv6Capable, _ = strconv.ParseBool(os.Getenv("IPV6_CAPABLE"))
|
2024-05-03 17:11:56 +00:00
|
|
|
}
|