alert

package
v0.16.21 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 10 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendSessionTokenRebindHint

func AppendSessionTokenRebindHint(message string) string

AppendSessionTokenRebindHint appends rebind hint to invalid access token messages. Mirrors TS appendSessionTokenRebindHint().

func IsCloudflareChallenge

func IsCloudflareChallenge(message string) bool

IsCloudflareChallenge detects Cloudflare challenge messages. Mirrors TS isCloudflareChallenge().

func IsTokenExpiredError

func IsTokenExpiredError(httpStatus int, message string) bool

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

func ShouldMarkAccountExpired(httpStatus int, message string) bool

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.

type ProxyAllFailedParams

type ProxyAllFailedParams struct {
	Model  string
	Reason string
}

type TokenExpiredParams

type TokenExpiredParams struct {
	AccountID  int64
	Username   *string
	SiteName   *string
	Detail     string
	HTTPStatus int // optional; 0 means classify from Detail alone
}

TokenExpiredParams holds parameters for reportTokenExpired.

Jump to

Keyboard shortcuts

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