Files
galaxy-game/authsession/internal/ports/config_provider.go
T
2026-04-08 16:23:07 +02:00

43 lines
1.3 KiB
Go

package ports
import (
"context"
"errors"
"fmt"
)
// ConfigProvider returns dynamic auth/session configuration required by later
// service workflows.
type ConfigProvider interface {
// LoadSessionLimit returns the current active-session-limit configuration.
// A nil ActiveSessionLimit means that the limit is disabled.
LoadSessionLimit(ctx context.Context) (SessionLimitConfig, error)
}
// SessionLimitConfig stores the active-session-limit configuration in a form
// that preserves “limit absent” as a first-class state.
type SessionLimitConfig struct {
// ActiveSessionLimit stores the configured limit when one is present. Nil
// means that no active-session limit is configured.
ActiveSessionLimit *int
}
// Validate reports whether SessionLimitConfig contains a valid limit value
// when one is configured.
func (c SessionLimitConfig) Validate() error {
if c.ActiveSessionLimit != nil && *c.ActiveSessionLimit <= 0 {
return errors.New("session limit config active session limit must be positive when configured")
}
return nil
}
// String returns a debug-friendly representation of SessionLimitConfig.
func (c SessionLimitConfig) String() string {
if c.ActiveSessionLimit == nil {
return "session_limit=disabled"
}
return fmt.Sprintf("session_limit=%d", *c.ActiveSessionLimit)
}