context

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package context contains additional functionality related to the gin-gonic context.

Index

Constants

This section is empty.

Variables

View Source
var (
	// KeyRequestID is the name of the context key holding the unique request ID.
	KeyRequestID = "request_id"

	// KeyLogger is the name of the context key holding the request-specific logger.
	KeyLogger = "logger"

	// KeyJWT is the name of the context key holding the JWT token.
	KeyJWT = "jwt"

	// KeySessionData is the name of the key where session data is stored.
	KeySessionData = "session_data"

	// KeySessionID is the name of the key where the session ID is stored.
	KeySessionID = "session_id"

	// KeyTranslator is the name of the key where the i18n translator object is stored.
	KeyTranslator = "translator"
)

Functions

func GetJWT

func GetJWT(c *gin.Context) *jwt.Token

GetJWT returns the JWT from the context.

func GetLogger

func GetLogger(c *gin.Context) zerolog.Logger

GetLogger returns the request ID from the context.

func GetRequestID

func GetRequestID(c *gin.Context) string

GetRequestID returns the request ID from the context.

func GetSessionID

func GetSessionID(c *gin.Context) string

GetSessionID returns the session ID stored in the context.

func GetTranslator

func GetTranslator(c *gin.Context) ut.Translator

GetTranslator returns the translator stored in the context.

func MarshalSessionData

func MarshalSessionData(c *gin.Context, data interface{}) error

MarshalSessionData saves the given data to the context.

func UnmarshalSessionData

func UnmarshalSessionData(c *gin.Context, obj interface{}) (bool, error)

UnmarshalSessionData retrieves session data from the context.

If session data was found and successfully unmarshaled into the given object, a true result is returned with a nil error. If no session data was found, a false result with a nil error is returned. If an error occurs while unmarshaling the data, a false result with an error is returned.

Types

This section is empty.

Jump to

Keyboard shortcuts

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