core

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const AcceptLanguageHeaderName = "Accept-Language"

AcceptLanguageHeaderName represents the header name of accept language

View Source
const ClientTimezoneOffsetHeaderName = "X-Timezone-Offset"

ClientTimezoneOffsetHeaderName represents the header name of client timezone offset

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiHandlerFunc

type ApiHandlerFunc func(*Context) (any, *errs.Error)

ApiHandlerFunc represents the api handler function

type Context

type Context struct {
	*gin.Context
}

Context represents the request and response context

func WrapContext

func WrapContext(ginCtx *gin.Context) *Context

WrapContext returns a context wrapped by this file

func (*Context) GetClientLocale added in v0.4.0

func (c *Context) GetClientLocale() string

GetClientLocale returns the client locale name

func (*Context) GetClientTimezoneOffset

func (c *Context) GetClientTimezoneOffset() (int16, error)

GetClientTimezoneOffset returns the client timezone offset

func (*Context) GetCurrentUid

func (c *Context) GetCurrentUid() int64

GetCurrentUid returns the current user uid by the current user token

func (*Context) GetRequestId

func (c *Context) GetRequestId() string

GetRequestId returns the current request id

func (*Context) GetResponseError

func (c *Context) GetResponseError() *errs.Error

GetResponseError returns the response error

func (*Context) GetTextualToken added in v0.4.0

func (c *Context) GetTextualToken() string

GetTextualToken returns the current user textual token

func (*Context) GetTokenClaims

func (c *Context) GetTokenClaims() *UserTokenClaims

GetTokenClaims returns the current user token

func (*Context) SetRequestId

func (c *Context) SetRequestId(requestId string)

SetRequestId sets the given request id to context

func (*Context) SetResponseError

func (c *Context) SetResponseError(error *errs.Error)

SetResponseError sets the response error

func (*Context) SetTextualToken added in v0.4.0

func (c *Context) SetTextualToken(token string)

SetTextualToken sets the given user token to context

func (*Context) SetTokenClaims

func (c *Context) SetTokenClaims(claims *UserTokenClaims)

SetTokenClaims sets the given user token to context

type DataHandlerFunc

type DataHandlerFunc func(*Context) ([]byte, string, *errs.Error)

DataHandlerFunc represents the handler function that returns byte array

type MiddlewareHandlerFunc

type MiddlewareHandlerFunc func(*Context)

MiddlewareHandlerFunc represents the middleware handler function

type ProxyHandlerFunc added in v0.3.0

type ProxyHandlerFunc func(*Context) (*httputil.ReverseProxy, *errs.Error)

ProxyHandlerFunc represents the reverse proxy handler function

type TokenType

type TokenType byte

TokenType represents token type

const (
	USER_TOKEN_TYPE_NORMAL         TokenType = 1
	USER_TOKEN_TYPE_REQUIRE_2FA    TokenType = 2
	USER_TOKEN_TYPE_EMAIL_VERIFY   TokenType = 3
	USER_TOKEN_TYPE_PASSWORD_RESET TokenType = 4
)

Token types

type UserTokenClaims

type UserTokenClaims struct {
	UserTokenId string    `json:"userTokenId"`
	Uid         int64     `json:"jti,string"`
	Username    string    `json:"username,omitempty"`
	Type        TokenType `json:"type"`
	IssuedAt    int64     `json:"iat"`
	ExpiresAt   int64     `json:"exp"`
}

UserTokenClaims represents user token

func (*UserTokenClaims) GetAudience added in v0.3.0

func (c *UserTokenClaims) GetAudience() (jwt.ClaimStrings, error)

GetAudience returns the audience of this token

func (*UserTokenClaims) GetExpirationTime added in v0.3.0

func (c *UserTokenClaims) GetExpirationTime() (*jwt.NumericDate, error)

GetExpirationTime returns the expiration time of this token

func (*UserTokenClaims) GetIssuedAt added in v0.3.0

func (c *UserTokenClaims) GetIssuedAt() (*jwt.NumericDate, error)

GetIssuedAt returns the issue time of this token

func (*UserTokenClaims) GetIssuer added in v0.3.0

func (c *UserTokenClaims) GetIssuer() (string, error)

GetIssuer returns the issuer of this token

func (*UserTokenClaims) GetNotBefore added in v0.3.0

func (c *UserTokenClaims) GetNotBefore() (*jwt.NumericDate, error)

GetNotBefore returns the earliest valid time of this token

func (*UserTokenClaims) GetSubject added in v0.3.0

func (c *UserTokenClaims) GetSubject() (string, error)

GetSubject returns the subject of this token

Jump to

Keyboard shortcuts

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