Добавить сессии в Valkey и вход через Basic с Bearer-токеном

This commit is contained in:
2026-10-06 15:08:39 +03:00
parent 3c1b63ed98
commit 9890482747
23 changed files with 1047 additions and 274 deletions
+13
View File
@@ -23,6 +23,8 @@ type Config struct {
ShutdownTimeout time.Duration
MaxBodyBytes int64
DatabaseURL string
SessionStoreURL string
SessionTTL time.Duration
}
// Lookup reads one variable, reporting whether it was set; os.LookupEnv
@@ -37,6 +39,7 @@ func Load(lookup Lookup) (Config, error) {
LogLevel: slog.LevelInfo,
ShutdownTimeout: 8 * time.Second,
MaxBodyBytes: 64 * 1024,
SessionTTL: time.Hour,
}
if v, ok := lookup("APP_HOST"); ok {
if strings.TrimSpace(v) == "" {
@@ -75,10 +78,20 @@ func Load(lookup Lookup) (Config, error) {
}
cfg.MaxBodyBytes = n
}
if v, ok := lookup("SESSION_TTL_SECONDS"); ok {
n, err := strconv.ParseUint(v, 10, 32)
if err != nil || n == 0 {
return Config{}, fmt.Errorf("SESSION_TTL_SECONDS must be a positive whole number of seconds, got %q", v)
}
cfg.SessionTTL = time.Duration(n) * time.Second
}
var err error
if cfg.DatabaseURL, err = secret(lookup, "DATABASE_URL_FILE"); err != nil {
return Config{}, err
}
if cfg.SessionStoreURL, err = secret(lookup, "SESSION_STORE_URL_FILE"); err != nil {
return Config{}, err
}
return cfg, nil
}