feat: more reorganisation and keys endpoint

This commit is contained in:
DaanSelen
2026-04-23 16:51:18 +02:00
parent c3aac38089
commit 417cecf43f
10 changed files with 131 additions and 95 deletions
+13 -53
View File
@@ -3,68 +3,27 @@ package bootstrap
import (
"os"
"path/filepath"
"slices"
"strconv"
)
type Environment struct {
// Items made for the presentation of ORBITS
Version string
Codename string
LogLevel string
DataDirectory string
ContentDirectory string
Hostname string
Port int
// Items made for the configuration of the server parts
DataDirectory string
ContentDirectory string
Hostname string
Port int
AuthenticationEnabled bool
// Items made for the server watchdog
WatchdogEnabled bool
WatchdogInterval int
WatchdogSyncMode string
}
var (
validSyncModes = []string{
"sync",
"strict",
"dry",
}
)
// part of environment checking
func safeStringGrab(key, fallback string) string {
if v, ok := os.LookupEnv(key); ok {
return v
}
return fallback
}
func safeIntGrab(key string, fallback int) int {
if v, ok := os.LookupEnv(key); ok {
if i, err := strconv.Atoi(v); err == nil {
return i
}
}
return fallback
}
func safeBoolGrab(key string, fallback bool) bool {
if v, ok := os.LookupEnv(key); ok {
if b, err := strconv.ParseBool(v); err == nil {
return b
}
}
return fallback
}
func safeSyncModeGrab(key, fallback string) string {
if v, ok := os.LookupEnv(key); ok {
if slices.Contains(validSyncModes, v) {
return v
}
}
return fallback
}
func GrabEnvironment() Environment {
cwd, err := os.Getwd()
if err != nil {
@@ -81,10 +40,11 @@ func GrabEnvironment() Environment {
LogLevel: safeStringGrab("LOG_LEVEL", "debug"),
// GIN API configuration
DataDirectory: safeStringGrab("DATA_DIR", fbBase),
ContentDirectory: safeStringGrab("CONTENT_DIR", fbContent),
Hostname: safeStringGrab("HOSTNAME", "0.0.0.0"),
Port: safeIntGrab("PORT", 8080),
DataDirectory: safeStringGrab("DATA_DIR", fbBase),
ContentDirectory: safeStringGrab("CONTENT_DIR", fbContent),
Hostname: safeStringGrab("HOSTNAME", "0.0.0.0"),
Port: safeIntGrab("PORT", 8080),
AuthenticationEnabled: safeBoolGrab("AUTH_ENABLED", true),
// watchdog configuration
// watchdog is the integrity checker/steward