middlewares

package
v1.10.6 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 19 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

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

func CountryMiddleware() gin.HandlerFunc

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

func GetTenantContext added in v1.10.0

func GetTenantContext(c *gin.Context) *types.TenantContext

GetTenantContext retrieves the TenantContext from the Gin context. Returns nil if no tenant context is set.

func LanguageMiddleware

func LanguageMiddleware() gin.HandlerFunc

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

func OrgAdminMiddleware added in v1.10.1

func OrgAdminMiddleware() gin.HandlerFunc

OrgAdminMiddleware is a middleware that allows access to Admin and OrgAdmin users. - Admin: Full access without restrictions - OrgAdmin: Access allowed, but handlers MUST validate that operations only affect their organization

The middleware sets "userClaims" in the context, and handlers should use: - userClaims.IsAdmin() to check if user has unrestricted access - userClaims.IsOrgAdmin() to check if user is an org admin (requires org validation) - userClaims.OrganizationID to get the user's organization for validation

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 RequireParentTenant added in v1.10.2

func RequireParentTenant() gin.HandlerFunc

RequireParentTenant is a middleware that ensures the tenant is a parent white label. Use this for endpoints that should only be accessible by parent tenants (master operations). Returns 400 if no tenant context exists. Returns 403 Forbidden if the tenant is not a parent.

func RequireTenant added in v1.10.0

func RequireTenant(client *mongo.Client) gin.HandlerFunc

RequireTenant is a middleware that ensures a valid tenant context exists. Use this for endpoints that require a resolved tenant. Returns 400 Bad Request if X-Tenant-Domain header is missing. Returns 404 Not Found if the domain is not found in white_labels.

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

func TenantResolver added in v1.10.0

func TenantResolver(client *mongo.Client) gin.HandlerFunc

TenantResolver is a middleware that resolves the tenant from X-Tenant-Domain header. It queries the white_labels collection to get the organization information and injects a TenantContext into the request context.

If no X-Tenant-Domain header is present, it falls back to the parent tenant. This ensures backward compatibility for clients that don't send the header.

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