Skip to content

타입과 상수

NumericDate

go
type NumericDate struct {
    time.Time
}

JWT 숫자 날짜 값 (Unix 타임스탬프). 유효 범위는 0 부터 253402300799 (9999-12-31 23:59:59 UTC) 까지.

struct

메서드

메서드시그니처설명
MarshalJSONfunc (date *NumericDate) MarshalJSON() ([]byte, error)Unix 타임스탬프 JSON 숫자로 직렬화; 제로 시간 또는 유효 범위를 벗어나면 null 반환
UnmarshalJSONfunc (date *NumericDate) UnmarshalJSON(b []byte) errorJSON 숫자 또는 문자열에서 Unix 타임스탬프 파싱; 음수 및 유효 범위를 벗어난 값 거부

StringOrSlice

go
type StringOrSlice []string

JSON 문자열 또는 JSON 배열에서 역직렬화되는 []string을 보관; 단일 요소 슬라이스는 JSON 문자열로, 다중 요소 슬라이스는 배열로 직렬화, RFC 7519 §4.1.3 준수.

type

메서드

메서드시그니처설명
MarshalJSONfunc (s StringOrSlice) MarshalJSON() ([]byte, error)단일 요소 슬라이스는 JSON 문자열로, 다중 요소는 배열로 직렬화 (RFC 7519 §4.1.3)
UnmarshalJSONfunc (s *StringOrSlice) UnmarshalJSON(b []byte) errorJSON 문자열 또는 배열에서 파싱

SigningMethod

go
type SigningMethod string

서명 알고리즘 타입.

type

ValidationError

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

필드 수준 검증 실패 오류.

struct

메서드

메서드시그니처설명
Errorfunc (e *ValidationError) Error() string오류 메시지
Unwrapfunc (e *ValidationError) Unwrap() error내부 오류 언래핑

RateLimiter

go
type RateLimiter struct { ... }

토큰 버킷 속도 제한기, RateLimitProvider 인터페이스 구현.

struct

메서드

메서드시그니처설명
Allowfunc (rl *RateLimiter) Allow(key string) bool단일 요청 확인
AllowNfunc (rl *RateLimiter) AllowN(key string, n int) booln 회 요청 확인
Resetfunc (rl *RateLimiter) Reset(key string)지정된 키 초기화
Closefunc (rl *RateLimiter) Close()리소스 해제

SystemClock

go
type SystemClock struct{}

시스템 클럭, ClockProvider의 기본 구현.

struct

메서드

메서드시그니처설명
Nowfunc (SystemClock) Now() time.Time현재 시스템 시간 반환

FixedClock

go
type FixedClock struct {
    T time.Time
}

고정 시간 클럭, 테스트용.

struct

필드

필드타입설명
Ttime.Time고정 시간 값

메서드

메서드시그니처설명
Nowfunc (c FixedClock) Now() time.Time고정 시간 반환

서명 알고리즘 상수

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"
)
상수알고리즘타입
SigningMethodHS256"HS256"HMAC-SHA256대칭
SigningMethodHS384"HS384"HMAC-SHA384대칭
SigningMethodHS512"HS512"HMAC-SHA512대칭
SigningMethodRS256"RS256"RSA-SHA256비대칭
SigningMethodRS384"RS384"RSA-SHA384비대칭
SigningMethodRS512"RS512"RSA-SHA512비대칭
SigningMethodPS256"PS256"RSA-PSS-SHA256비대칭
SigningMethodPS384"PS384"RSA-PSS-SHA384비대칭
SigningMethodPS512"PS512"RSA-PSS-SHA512비대칭
SigningMethodES256"ES256"ECDSA-SHA256비대칭
SigningMethodES384"ES384"ECDSA-SHA384비대칭
SigningMethodES512"ES512"ECDSA-SHA512비대칭

토큰 타입 상수

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

RegisteredClaims.TokenType 필드에 기록되는 토큰 타입 상수.

상수설명
TokenTypeAccess"access"액세스 토큰
TokenTypeRefresh"refresh"리프레시 토큰