Skip to content

Types & Constants ​

NumericDate ​

go
type NumericDate struct {
    time.Time
}

JWT numeric date value (Unix timestamp). Valid range: 0 to 253402300799 (9999-12-31 23:59:59 UTC).

The struct embeds time.Time (the Time field), so a NumericDate value can call time.Time methods directly (such as Unix(), Before()) for time comparisons and arithmetic.

struct

Methods ​

MethodSignatureDescription
MarshalJSONfunc (date NumericDate) MarshalJSON() ([]byte, error)Serialize to Unix timestamp JSON number; returns null for zero time or out-of-range values
UnmarshalJSONfunc (date *NumericDate) UnmarshalJSON(b []byte) errorParse Unix timestamp from JSON number or string; rejects negative and out-of-range values

StringOrSlice ​

go
type StringOrSlice []string

Holds a []string that unmarshals from either a JSON string or a JSON array; a single-element slice marshals as a JSON string and a multi-element slice as an array, conforming to RFC 7519 §4.1.3.

type

Methods ​

MethodSignatureDescription
MarshalJSONfunc (s StringOrSlice) MarshalJSON() ([]byte, error)Single-element slice marshals as a JSON string, multi-element as an array (RFC 7519 §4.1.3)
UnmarshalJSONfunc (s *StringOrSlice) UnmarshalJSON(b []byte) errorParse from a JSON string or array

SigningMethod ​

go
type SigningMethod string

Signing algorithm type.

type

ValidationError ​

go
type ValidationError struct {
    Field   string
    Message string
    Err     error
}

Field-level validation failure error. On the Create / Parse paths it appears as the underlying cause wrapped by ErrInvalidClaims and can be extracted with errors.As; see the error handling guide.

struct

Fields ​

FieldTypeDescription
FieldstringName of the field or claim that failed validation (e.g. user_id, extra.color)
MessagestringWhy the field is invalid (e.g. exceeds the 256-character limit, suspicious pattern detected)
ErrerrorOptional underlying error wrapped by this failure; Unwrap returns it so errors.Is / errors.As can traverse it; nil when there is no wrapped cause

Methods ​

MethodSignatureDescription
Errorfunc (e *ValidationError) Error() stringError message (field name, reason, and wrapped error)
Unwrapfunc (e *ValidationError) Unwrap() errorReturns the underlying error stored in Err

RateLimiter ​

go
type RateLimiter struct { ... }

Token bucket rate limiter, implements RateLimitProvider.

Uses the token bucket algorithm: tokens are refilled proportionally to elapsed time (rather than reset on a fixed window), and residual time is retained after refilling to keep the rate uniform; each request consumes a token, and requests are denied when tokens are insufficient.

Internally tracks at most 10,000 rate limit keys (maxBuckets). When the limit is reached, it first evicts expired buckets (inactive for more than 2× the window); if still full, it batch-evicts the approximately oldest 10%, amortizing the O(n) scan cost.

struct

Methods ​

MethodSignatureDescription
Allowfunc (rl *RateLimiter) Allow(key string) boolCheck single request
AllowNfunc (rl *RateLimiter) AllowN(key string, n int) boolCheck n requests
Resetfunc (rl *RateLimiter) Reset(key string)Reset specified key
Closefunc (rl *RateLimiter) Close()Release resources

SystemClock ​

go
type SystemClock struct{}

System clock, default implementation of ClockProvider.

struct

Methods ​

MethodSignatureDescription
Nowfunc (SystemClock) Now() time.TimeReturns current system time

FixedClock ​

go
type FixedClock struct {
    T time.Time
}

Fixed time clock for testing.

struct

Fields ​

FieldTypeDescription
Ttime.TimeFixed time value

Methods ​

MethodSignatureDescription
Nowfunc (c FixedClock) Now() time.TimeReturns fixed time

Signing Algorithm Constants ​

go
const (
    SigningMethodHS256 SigningMethod = "HS256"
    SigningMethodHS384 SigningMethod = "HS384"
    SigningMethodHS512 SigningMethod = "HS512"

    SigningMethodRS256 SigningMethod = "RS256"
    SigningMethodRS384 SigningMethod = "RS384"
    SigningMethodRS512 SigningMethod = "RS512"

    SigningMethodPS256 SigningMethod = "PS256"
    SigningMethodPS384 SigningMethod = "PS384"
    SigningMethodPS512 SigningMethod = "PS512"

    SigningMethodES256 SigningMethod = "ES256"
    SigningMethodES384 SigningMethod = "ES384"
    SigningMethodES512 SigningMethod = "ES512"
)
ConstantValueAlgorithmType
SigningMethodHS256"HS256"HMAC-SHA256Symmetric
SigningMethodHS384"HS384"HMAC-SHA384Symmetric
SigningMethodHS512"HS512"HMAC-SHA512Symmetric
SigningMethodRS256"RS256"RSA-SHA256Asymmetric
SigningMethodRS384"RS384"RSA-SHA384Asymmetric
SigningMethodRS512"RS512"RSA-SHA512Asymmetric
SigningMethodPS256"PS256"RSA-PSS-SHA256Asymmetric
SigningMethodPS384"PS384"RSA-PSS-SHA384Asymmetric
SigningMethodPS512"PS512"RSA-PSS-SHA512Asymmetric
SigningMethodES256"ES256"ECDSA-SHA256Asymmetric
SigningMethodES384"ES384"ECDSA-SHA384Asymmetric
SigningMethodES512"ES512"ECDSA-SHA512Asymmetric

Token Type Constants ​

go
const (
    TokenTypeAccess  = "access"
    TokenTypeRefresh = "refresh"
)

Token type constants written to the RegisteredClaims.TokenType field.

ConstantValueDescription
TokenTypeAccess"access"Access token
TokenTypeRefresh"refresh"Refresh token