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).

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.

struct

Methods

MethodSignatureDescription
Errorfunc (e *ValidationError) Error() stringError message
Unwrapfunc (e *ValidationError) Unwrap() errorUnwrap inner error

RateLimiter

go
type RateLimiter struct { ... }

Token bucket rate limiter, implements RateLimitProvider.

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