middleware

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SkipAccessLog = "_skip_access_log_"

SkipAccessLog is a flag to skip access log

Functions

func AccessLogger

func AccessLogger(pathPatterns ...*regexp.Regexp) gin.HandlerFunc

AccessLogger a Logger middleware that will write the access logs to stdout or file.

func Auth

func Auth(c *gin.Context)

Auth authenticate users.

func CORS

func CORS() gin.HandlerFunc

CORS creates a new CORS Gin middleware.

func ContextWithAcceptLanguage

func ContextWithAcceptLanguage(c *gin.Context)

ContextWithAcceptLanguage store accept language into c.Request.Context.

func ErrResp

func ErrResp(c *gin.Context, key string, opts ...i18n.Option) map[string]any

ErrResp response the localized message according to the set key

func RespInternal

func RespInternal(c *gin.Context, msg ...string)

RespInternal gin response internal server error with msg.

Types

type Token

type Token struct {
	jwt.RegisteredClaims
	UserId    string `json:"userId"`
	ChannelId string `json:"channelId"`
	Email     string `json:"email"`
	Username  string `json:"username"`
}

type TokenManager

type TokenManager struct {
	TokenSecretKey         string        `mapstructure:"token_secret_key"`
	AccessTokenExpiration  time.Duration `mapstructure:"access_token_expiration"`
	RefreshTokenExpiration time.Duration `mapstructure:"refresh_token_expiration"`
}

func NewTokenManager

func NewTokenManager() (*TokenManager, error)

func (*TokenManager) GenerateAccessToken

func (t *TokenManager) GenerateAccessToken(token *Token) (string, error)

func (*TokenManager) GenerateRefreshToken

func (t *TokenManager) GenerateRefreshToken(token *Token) (string, error)

func (*TokenManager) ValidateToken

func (t *TokenManager) ValidateToken(tokenString string) (*Token, error)

type Tokens

type Tokens struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
}

func GenerateTokens

func GenerateTokens(token *Token) (*Tokens, error)

GenerateTokens generate access token and refresh token

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳