middlewares

package
v1.6.21 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdminMiddleware

func AdminMiddleware() gin.HandlerFunc

AdminMiddleware is a middleware that checks if the user is an admin

func AuthMiddleware

func AuthMiddleware() gin.HandlerFunc

AuthMiddleware is a middleware that checks if the user is authenticated

func CORSMiddleware added in v1.6.16

func CORSMiddleware() gin.HandlerFunc

CORSMiddleware is a middleware function that adds Cross-Origin Resource Sharing (CORS) headers to the response. It allows requests from any origin and includes common headers and methods used in HTTP requests. If the request method is OPTIONS, it responds with a 204 No Content status code. This middleware should be used to enable CORS support in your application.

func CountryMiddleware added in v1.6.18

func CountryMiddleware() gin.HandlerFunc

CountryMiddleware is a middleware that extracts the country from the X-Country header

func LanguageMiddleware added in v1.5.5

func LanguageMiddleware() gin.HandlerFunc

LanguageMiddleware is a middleware that extracts the language from the Content-Language header

func ParseIntIDMiddlware

func ParseIntIDMiddlware() gin.HandlerFunc

ParseIntIDMiddlware is a middleware function that parses an integer ID from the request parameter and sets it in the context. If the ID is invalid, it returns a JSON response with a status code of 400 Bad Request and an error message. The middleware function is designed to be used with the Gin framework.

func ParseMongoIDMiddleware

func ParseMongoIDMiddleware(paramName ...string) gin.HandlerFunc

ParseMongoIDMiddleware is a middleware function that parses a MongoDB ObjectID from the request parameter and sets it in the context. If the ID is invalid, it returns a JSON response with a status code of 400 Bad Request and an error message. The middleware function is designed to be used with the Gin framework.

func ParsePaginationParams

func ParsePaginationParams() gin.HandlerFunc

ParsePaginationParams is a middleware function that parses pagination parameters from the request. It extracts the pagination parameters from the request and sets them in the context for further processing. If there is an error while parsing the parameters, it returns a bad request error.

func RoleBasedAuthMiddleware

func RoleBasedAuthMiddleware(allowedRoles []enums.Role) gin.HandlerFunc

RoleBasedAuthMiddleware is a middleware that checks if the user has one of the specified roles

func SanitizeMiddleware

func SanitizeMiddleware() gin.HandlerFunc

SanitizeMiddleware is a middleware that sanitizes input to prevent XSS attacks

Types

type Key

type Key int
const UserClaimsKey Key = iota

Jump to

Keyboard shortcuts

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