Vendor SharedCode locally
Docker / Docker Build & Push (push) Failing after 1m19s
Lint / Lint (push) Successful in 15s
Tests / Go backend (push) Successful in 19s
Tests / Dashboard checks (push) Successful in 18s

This commit is contained in:
Gabriel20xx committed 2026-08-06 15:52:56 +02:00
1 parent a8c51b8484
commit 6eb8f4ad60
88 files changed
+9708 -275

No files matched your search

+71
View File
@@ -0,0 +1,71 @@
// Package config contains small, dependency-free environment helpers shared
// by the Go services. It intentionally does not define an application's full
// configuration struct.
package config
import (
"fmt"
"os"
"strconv"
"strings"
"time"
)
// String returns the environment value or fallback when the variable is empty.
func String(key, fallback string) string {
if value := strings.TrimSpace(os.Getenv(key)); value != "" {
return value
}
return fallback
}
// Required returns a trimmed environment value or an actionable error.
func Required(key string) (string, error) {
value := strings.TrimSpace(os.Getenv(key))
if value == "" {
return "", fmt.Errorf("%s is required", key)
}
return value, nil
}
// Bool returns a parsed boolean environment value or fallback for an unset or
// invalid value. Invalid values are deliberately non-fatal for optional flags.
func Bool(key string, fallback bool) bool {
value := strings.TrimSpace(os.Getenv(key))
if value == "" {
return fallback
}
parsed, err := strconv.ParseBool(value)
if err != nil {
return fallback
}
return parsed
}
// Int returns a parsed integer environment value or fallback for an unset or
// invalid value. Callers should validate application-specific ranges.
func Int(key string, fallback int) int {
value := strings.TrimSpace(os.Getenv(key))
if value == "" {
return fallback
}
parsed, err := strconv.Atoi(value)
if err != nil {
return fallback
}
return parsed
}
// Duration returns a parsed duration environment value or fallback for an
// unset or invalid value.
func Duration(key string, fallback time.Duration) time.Duration {
value := strings.TrimSpace(os.Getenv(key))
if value == "" {
return fallback
}
parsed, err := time.ParseDuration(value)
if err != nil {
return fallback
}
return parsed
}