Documentation
¶
Index ¶
- func AppendSessionTokenRebindHint(message string) string
- func IsCloudflareChallenge(message string) bool
- func IsTokenExpiredError(httpStatus int, message string) bool
- func ReportLowBalance(cfg *config.RuntimeSettings, db *sqlx.DB, params LowBalanceParams)
- func ReportProxyAllFailed(cfg *config.RuntimeSettings, db *sqlx.DB, params ProxyAllFailedParams)
- func ReportTokenExpired(cfg *config.RuntimeSettings, db *sqlx.DB, params TokenExpiredParams)
- func ShouldMarkAccountExpired(httpStatus int, message string) bool
- type LowBalanceParams
- type ProxyAllFailedParams
- type TokenExpiredParams
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendSessionTokenRebindHint ¶
AppendSessionTokenRebindHint appends rebind hint to invalid access token messages. Mirrors TS appendSessionTokenRebindHint().
func IsCloudflareChallenge ¶
IsCloudflareChallenge detects Cloudflare challenge messages. Mirrors TS isCloudflareChallenge().
func IsTokenExpiredError ¶
IsTokenExpiredError reports confirmed credential expiry/invalidity. After it matches ShouldMarkAccountExpired (ClassExpired only). Auto-relogin callers that need broader 401/unauthorized heuristics must use local shouldAttemptAutoRelogin* patterns, not this gate alone.
func ReportLowBalance ¶
func ReportLowBalance(cfg *config.RuntimeSettings, db *sqlx.DB, params LowBalanceParams)
ReportLowBalance fires a real-time low-balance alert when an account's balance drops below a threshold right after a refresh. Deduped per account per lowBalanceEventWindow via the events table (no spam while low).
G1: the TS original only counted lowBalanceAccounts in a daily summary (balance < 1) — it never fired a real-time trigger. metapi-go does better: the alert lands as soon as the refresh observes the low balance.
func ReportProxyAllFailed ¶
func ReportProxyAllFailed(cfg *config.RuntimeSettings, db *sqlx.DB, params ProxyAllFailedParams)
ReportProxyAllFailed reports a proxy all-failed event. Mirrors TS reportProxyAllFailed(). Deduped per model: at most one event + notification per cooldown window (cfg.NotifyCooldownSec, floored at proxyAllFailedCooldownFloorMs) so a dead upstream cannot spam operators on every request.
func ReportTokenExpired ¶
func ReportTokenExpired(cfg *config.RuntimeSettings, db *sqlx.DB, params TokenExpiredParams)
ReportTokenExpired reports a confirmed token expiration event and marks the account expired. Defense-in-depth : even if a caller forgets ShouldMarkAccountExpired, this function no-ops unless classification confirms ClassExpired. Generic 401, network, 429, and 5xx must never force-mark accounts.status='expired'. Mirrors TS reportTokenExpired() with a hard mark guard.
func ShouldMarkAccountExpired ¶
ShouldMarkAccountExpired is the guard before writing accounts.status='expired'. Only ClassExpired marks. Prefer this at ReportTokenExpired call sites; ReportTokenExpired also self-guards for defense-in-depth.
Types ¶
type LowBalanceParams ¶
type LowBalanceParams struct {
AccountID int64
Username *string
SiteName *string
Balance float64 // current balance after refresh
Threshold float64 // alert when Balance < Threshold
}
LowBalanceParams holds parameters for reportLowBalance.