feat:level4

This commit is contained in:
Оля Мороз
2026-10-20 18:35:44 +03:00
parent 4349a539d9
commit ae53d39ccc
20 changed files with 775 additions and 26 deletions
+17
View File
@@ -1,6 +1,8 @@
package config
import (
"crypto/rand"
"encoding/hex"
"os"
"strconv"
"time"
@@ -15,6 +17,7 @@ type Config struct {
SessionTTL time.Duration
SessionStore string // "postgres" | "redis"
RedisRequired bool
InstanceID string
}
func getenv(key, def string) string {
@@ -59,6 +62,11 @@ func Load() Config {
cacheURL = readSecretFromFile(os.Getenv("CACHE_URL_FILE"))
}
instanceID := os.Getenv("INSTANCE_ID")
if instanceID == "" {
instanceID = "api-" + randomShortID()
}
store := getenv("SESSION_STORE", "postgres")
return Config{
Host: getenv("APP_HOST", "0.0.0.0"),
@@ -69,5 +77,14 @@ func Load() Config {
SessionTTL: time.Duration(ttl) * time.Second,
SessionStore: store,
RedisRequired: store == "redis",
InstanceID: instanceID,
}
}
func randomShortID() string {
b := make([]byte, 6)
if _, err := rand.Read(b); err != nil {
return "unknown"
}
return hex.EncodeToString(b)
}