ports

package
v0.0.0-...-addc432 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2026 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildBlocklistMiddleware

func BuildBlocklistMiddleware(config BlocklistConfig) func(http.HandlerFunc) http.HandlerFunc

func BuildCORSHandler

func BuildCORSHandler(allowedSuffixes *DomainSuffixes) http.HandlerFunc

func BuildCORSMiddleware

func BuildCORSMiddleware(allowedSuffixes *DomainSuffixes) func(http.HandlerFunc) http.HandlerFunc

func BuildRegisterUserVisitMiddleware

func BuildRegisterUserVisitMiddleware(registerUserVisit app.RegisterUserVisit) func(http.HandlerFunc) http.HandlerFunc

func ComposeMiddlewares

func ComposeMiddlewares(middlewares ...func(http.HandlerFunc) http.HandlerFunc) func(http.HandlerFunc) http.HandlerFunc

func HistoryToRainbowHistoryData

func HistoryToRainbowHistoryData(history []domain.PlayerPIT) ([]byte, error)

func IPHashKeyFunc

func IPHashKeyFunc(r *http.Request) string

func MakeAnonymousLoginHandler

func MakeAnonymousLoginHandler(
	login app.AnonymousLogin,
	nowFunc func() time.Time,
	allowedOrigins *DomainSuffixes,
	rootLogger *slog.Logger,
	sentryMiddleware func(http.HandlerFunc) http.HandlerFunc,
	blocklistConfig BlocklistConfig,
) (http.HandlerFunc, func())

MakeAnonymousLoginHandler returns a handler for POST /v1/auth/anonymous/login. Body: { userId }. Response: a fresh session payload.

func MakeAuthRefreshHandler

func MakeAuthRefreshHandler(
	refresh app.RefreshSession,
	nowFunc func() time.Time,
	allowedOrigins *DomainSuffixes,
	rootLogger *slog.Logger,
	sentryMiddleware func(http.HandlerFunc) http.HandlerFunc,
	blocklistConfig BlocklistConfig,
) (http.HandlerFunc, func())

MakeAuthRefreshHandler returns a handler for POST /v1/auth/refresh. Accepts a Bearer token (which may be past expires_at but within refresh_until). Tier-agnostic: the underlying use case branches on the stored session.

func MakeGetAccountByUUIDHandler

func MakeGetAccountByUUIDHandler(
	getAccountByUUID app.GetAccountByUUID,
	registerUserVisit app.RegisterUserVisit,
	allowedOrigins *DomainSuffixes,
	rootLogger *slog.Logger,
	sentryMiddleware func(http.HandlerFunc) http.HandlerFunc,
	bearerAuthMiddleware func(http.HandlerFunc) http.HandlerFunc,
	blocklistConfig BlocklistConfig,
) (http.HandlerFunc, func())

func MakeGetAccountByUsernameHandler

func MakeGetAccountByUsernameHandler(
	getAccountByUsername app.GetAccountByUsername,
	registerUserVisit app.RegisterUserVisit,
	allowedOrigins *DomainSuffixes,
	rootLogger *slog.Logger,
	sentryMiddleware func(http.HandlerFunc) http.HandlerFunc,
	bearerAuthMiddleware func(http.HandlerFunc) http.HandlerFunc,
	blocklistConfig BlocklistConfig,
) (http.HandlerFunc, func())

func MakeGetHistoryHandler

func MakeGetHistoryHandler(
	getHistory app.GetHistory,
	registerUserVisit app.RegisterUserVisit,
	allowedOrigins *DomainSuffixes,
	rootLogger *slog.Logger,
	sentryMiddleware func(http.HandlerFunc) http.HandlerFunc,
	bearerAuthMiddleware func(http.HandlerFunc) http.HandlerFunc,
	blocklistConfig BlocklistConfig,
) (http.HandlerFunc, func())

func MakeGetPlayerDataHandler

func MakeGetPlayerDataHandler(
	getAndPersistPlayerWithCache app.GetAndPersistPlayerWithCache,
	registerUserVisit app.RegisterUserVisit,
	rootLogger *slog.Logger,
	sentryMiddleware func(http.HandlerFunc) http.HandlerFunc,
	bearerAuthMiddleware func(http.HandlerFunc) http.HandlerFunc,
	blocklistConfig BlocklistConfig,
	deprecated bool,
) (http.HandlerFunc, func())

func MakeGetPrestigesHandler

func MakeGetPrestigesHandler(
	findMilestoneAchievements app.FindMilestoneAchievements,
	registerUserVisit app.RegisterUserVisit,
	allowedOrigins *DomainSuffixes,
	rootLogger *slog.Logger,
	sentryMiddleware func(http.HandlerFunc) http.HandlerFunc,
	blocklistConfig BlocklistConfig,
) (http.HandlerFunc, func())

func MakeGetSessionAtHandler

func MakeGetSessionAtHandler(
	getSessionAt app.GetSessionAt,
	registerUserVisit app.RegisterUserVisit,
	allowedOrigins *DomainSuffixes,
	rootLogger *slog.Logger,
	sentryMiddleware func(http.HandlerFunc) http.HandlerFunc,
	bearerAuthMiddleware func(http.HandlerFunc) http.HandlerFunc,
	blocklistConfig BlocklistConfig,
) (http.HandlerFunc, func())

func MakeGetSessionsHandler

func MakeGetSessionsHandler(
	getPlayerPITs app.GetPlayerPITs,
	computeSessions app.ComputeSessions,
	registerUserVisit app.RegisterUserVisit,
	allowedOrigins *DomainSuffixes,
	rootLogger *slog.Logger,
	sentryMiddleware func(http.HandlerFunc) http.HandlerFunc,
	bearerAuthMiddleware func(http.HandlerFunc) http.HandlerFunc,
	blocklistConfig BlocklistConfig,
) (http.HandlerFunc, func())

func MakeGetTagsHandler

func MakeGetTagsHandler(
	getTags app.GetTags,
	registerUserVisit app.RegisterUserVisit,
	rootLogger *slog.Logger,
	sentryMiddleware func(http.HandlerFunc) http.HandlerFunc,
	bearerAuthMiddleware func(http.HandlerFunc) http.HandlerFunc,
	blocklistConfig BlocklistConfig,
) (http.HandlerFunc, func())

func MakeGetWrappedHandler

func MakeGetWrappedHandler(
	getPlayerPITs app.GetPlayerPITs,
	computeSessions app.ComputeSessions,
	registerUserVisit app.RegisterUserVisit,
	allowedOrigins *DomainSuffixes,
	rootLogger *slog.Logger,
	sentryMiddleware func(http.HandlerFunc) http.HandlerFunc,
	bearerAuthMiddleware func(http.HandlerFunc) http.HandlerFunc,
	blocklistConfig BlocklistConfig,
) (http.HandlerFunc, func())

func MakePrismNoticesHandler

func MakePrismNoticesHandler(
	getPrismNotices app.GetPrismNotices,
	registerUserVisit app.RegisterUserVisit,
	rootLogger *slog.Logger,
	sentryMiddleware func(http.HandlerFunc) http.HandlerFunc,
	bearerAuthMiddleware func(http.HandlerFunc) http.HandlerFunc,
	blocklistConfig BlocklistConfig,
) (http.HandlerFunc, func())

func NewBearerAuthMiddleware

func NewBearerAuthMiddleware(validate app.ValidateSession) func(http.HandlerFunc) http.HandlerFunc

NewBearerAuthMiddleware returns a middleware that validates an Authorization: Bearer <session-id> header against the auth session store when present. It is passive: requests without an Authorization header pass through unchanged (preserving the legacy X-User-Id flow). When a header IS present but the session is unknown or expired, the request is rejected with 401 — otherwise a bearer would be silently ignored, which would let clients downgrade to the un-authenticated path just by sending a bad token.

func NewRateLimitMiddleware

func NewRateLimitMiddleware(rateLimiter ratelimiting.RequestRateLimiter, onLimitExceeded http.HandlerFunc) func(http.HandlerFunc) http.HandlerFunc

func NewReportingMetaMiddleware

func NewReportingMetaMiddleware(port string) func(http.HandlerFunc) http.HandlerFunc

func NewRequestLoggerMiddleware

func NewRequestLoggerMiddleware(logger *slog.Logger) func(next http.HandlerFunc) http.HandlerFunc

func PlayerToPrismPlayerDataResponseData

func PlayerToPrismPlayerDataResponseData(player *domain.PlayerPIT) ([]byte, error)

func PlayerToRainbowPlayerDataPITData

func PlayerToRainbowPlayerDataPITData(player *domain.PlayerPIT) ([]byte, error)

func SessionsToRainbowSessionsData

func SessionsToRainbowSessionsData(sessions []domain.Session) ([]byte, error)

func UserIDKeyFunc

func UserIDKeyFunc(r *http.Request) string

Types

type AuthContext

type AuthContext struct {
	SessionID    string
	IdentityType domain.AuthSessionIdentityType
	IdentityKey  string
}

AuthContext is what the bearer middleware stashes into the request context when a valid Authorization header is present. Absent when the request had no Authorization header (legacy X-User-Id callers).

func AuthFromContext

func AuthFromContext(ctx context.Context) (AuthContext, bool)

AuthFromContext returns the auth context attached by the bearer middleware, or (zero, false) when no bearer was sent.

type BlocklistConfig

type BlocklistConfig struct {
	IPs          []string
	UserAgents   []string
	UserIDs      []string
	SHA256HexIPs []string
}

type Client

type Client struct {
	RawType    string
	RawVersion string
	Type       string
	Version    string
}

Client is the normalized identity of the calling client, derived from the X-Client-Type and X-Client-Version request headers. Raw values are retained (truncated) for logging; Type and Version are the bounded, allowlisted values safe to use as metric labels.

func GetClient

func GetClient(r *http.Request) Client

GetClient reads and normalizes the client identity from the request headers.

func (Client) MetricAttributes

func (c Client) MetricAttributes() []attribute.KeyValue

MetricAttributes returns the bounded client labels for metric instruments. Kept here so the call sites stay consistent.

type DomainSuffixes

type DomainSuffixes struct {
	// contains filtered or unexported fields
}

func NewDomainSuffixes

func NewDomainSuffixes(suffixes ...string) (*DomainSuffixes, error)

func (*DomainSuffixes) AnyMatch

func (suffixes *DomainSuffixes) AnyMatch(origin string) bool

type HypixelAPIErrorResponse

type HypixelAPIErrorResponse struct {
	Success bool   `json:"success"`
	Cause   string `json:"cause"`
}

type IP

type IP string

func GetIP

func GetIP(r *http.Request) IP

func (IP) Hash

func (ip IP) Hash() string

func (IP) String

func (ip IP) String() string

type UserID

type UserID string

UserID represents a user identifier extracted from an HTTP request.

func GetUserID

func GetUserID(r *http.Request) UserID

func (UserID) LowCardinalityString

func (u UserID) LowCardinalityString() string

LowCardinalityString returns a low cardinality representation of the user ID. Returns "<missing>" for empty user IDs. For IDs shorter than 20 characters, it returns "<short-user-id>". Otherwise, it returns the full user ID (which is truncated to a maximum of 50 characters).

func (UserID) String

func (u UserID) String() string

String returns the full user ID string. Returns "<missing>" for empty user IDs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL