middleware

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LanguageContextKey is the key for storing language in context
	LanguageContextKey = "language"
	// DefaultLanguage is the default language
	DefaultLanguage = "en"
)

Variables

This section is empty.

Functions

func ClearLanguageCookie

func ClearLanguageCookie(c *gin.Context)

ClearLanguageCookie clears the language preference cookie

func DatabaseHealthCheck

func DatabaseHealthCheck() gin.HandlerFunc

DatabaseHealthCheck middleware checks database connectivity and returns a friendly error page if the database is down

func GetCurrentUser

func GetCurrentUser(c *gin.Context) (uint, string, string, bool)

GetCurrentUser retrieves the current user from context

func GetLanguage

func GetLanguage(c *gin.Context) string

GetLanguage gets the current language from context

func LoadOpenAPIMiddleware

func LoadOpenAPIMiddleware() gin.HandlerFunc

LoadOpenAPIMiddleware creates the OpenAPI validation middleware

func OptionalAuth

func OptionalAuth(jwtManager *auth.JWTManager) gin.HandlerFunc

OptionalAuth is middleware that validates tokens if present but doesn't require them

func RequestID

func RequestID() gin.HandlerFunc

RequestID adds a unique request ID to each request

func RequireAdminAccess

func RequireAdminAccess(rbac *auth.RBAC) gin.HandlerFunc

RequireAdminAccess is a convenience function for admin-only routes

func RequireAdminGroup

func RequireAdminGroup() gin.HandlerFunc

RequireAdminGroup checks if the user is in the admin group

func RequireAgentAccess

func RequireAgentAccess(rbac *auth.RBAC) gin.HandlerFunc

RequireAgentAccess allows both admins and agents

func RequireAnyPermission

func RequireAnyPermission(rbac *auth.RBAC, permissions ...auth.Permission) gin.HandlerFunc

RequireAnyPermission checks if the user has any of the required permissions

func RequirePermission

func RequirePermission(rbac *auth.RBAC, permission auth.Permission) gin.HandlerFunc

RequirePermission checks if the user has the required permission

func RequireRole

func RequireRole(roles ...string) gin.HandlerFunc

RequireRole checks if the user has the required role

func RequireTicketAccess

func RequireTicketAccess(rbac *auth.RBAC) gin.HandlerFunc

RequireTicketAccess checks if the user can access a specific ticket

func SessionMiddleware

func SessionMiddleware(jwtManager *auth.JWTManager) gin.HandlerFunc

SessionMiddleware validates JWT tokens from cookies or Authorization header

func SetLanguageCookie

func SetLanguageCookie(c *gin.Context, lang string)

SetLanguageCookie sets the language preference cookie

func T

func T(c *gin.Context, key string, args ...interface{}) string

T translates a key in the current language

func TranslateError

func TranslateError(c *gin.Context, key string, args ...interface{}) string

TranslateError translates an error message

func TranslateSuccess

func TranslateSuccess(c *gin.Context, key string, args ...interface{}) string

TranslateSuccess translates a success message

func TranslateValidation

func TranslateValidation(c *gin.Context, key string, args ...interface{}) string

TranslateValidation translates a validation message

Types

type AuthMiddleware

type AuthMiddleware struct {
	// contains filtered or unexported fields
}

func NewAuthMiddleware

func NewAuthMiddleware(jwtManager *auth.JWTManager) *AuthMiddleware

func (*AuthMiddleware) CanAccessTicket

func (m *AuthMiddleware) CanAccessTicket(c *gin.Context, ticketOwnerID uint) bool

func (*AuthMiddleware) GetUserID

func (m *AuthMiddleware) GetUserID(c *gin.Context) (uint, bool)

func (*AuthMiddleware) GetUserRole

func (m *AuthMiddleware) GetUserRole(c *gin.Context) (string, bool)

func (*AuthMiddleware) IsAuthenticated

func (m *AuthMiddleware) IsAuthenticated(c *gin.Context) bool

func (*AuthMiddleware) OptionalAuth

func (m *AuthMiddleware) OptionalAuth() gin.HandlerFunc

func (*AuthMiddleware) RequireAuth

func (m *AuthMiddleware) RequireAuth() gin.HandlerFunc

func (*AuthMiddleware) RequirePermission

func (m *AuthMiddleware) RequirePermission(permission auth.Permission) gin.HandlerFunc

func (*AuthMiddleware) RequireRole

func (m *AuthMiddleware) RequireRole(roles ...string) gin.HandlerFunc

type I18nMiddleware

type I18nMiddleware struct {
	// contains filtered or unexported fields
}

I18nMiddleware handles language detection and sets it in context

func NewI18nMiddleware

func NewI18nMiddleware() *I18nMiddleware

NewI18nMiddleware creates a new i18n middleware

func (*I18nMiddleware) Handle

func (m *I18nMiddleware) Handle() gin.HandlerFunc

Handle returns the middleware handler function

type MediaType

type MediaType struct {
	Schema Schema `yaml:"schema"`
}

MediaType represents an OpenAPI media type

type OpenAPISpec

type OpenAPISpec struct {
	OpenAPI string                 `yaml:"openapi"`
	Info    map[string]interface{} `yaml:"info"`
	Paths   map[string]PathItem    `yaml:"paths"`
}

OpenAPISpec represents a simplified OpenAPI specification

type OpenAPIValidator

type OpenAPIValidator struct {
	// contains filtered or unexported fields
}

OpenAPIValidator provides OpenAPI contract validation

func NewOpenAPIValidator

func NewOpenAPIValidator(specPath string) (*OpenAPIValidator, error)

NewOpenAPIValidator creates a new OpenAPI validator from the spec file

func (*OpenAPIValidator) ValidateResponse

func (v *OpenAPIValidator) ValidateResponse() gin.HandlerFunc

ValidateResponse validates that a response matches the OpenAPI spec

type Operation

type Operation struct {
	OperationID string              `yaml:"operationId"`
	Responses   map[string]Response `yaml:"responses"`
	RequestBody *RequestBody        `yaml:"requestBody,omitempty"`
}

Operation represents an OpenAPI operation

type PathItem

type PathItem map[string]Operation

PathItem represents an OpenAPI path item

type RequestBody

type RequestBody struct {
	Required bool                 `yaml:"required"`
	Content  map[string]MediaType `yaml:"content"`
}

RequestBody represents an OpenAPI request body

type Response

type Response struct {
	Description string               `yaml:"description"`
	Content     map[string]MediaType `yaml:"content,omitempty"`
}

Response represents an OpenAPI response

type Schema

type Schema struct {
	Type       string            `yaml:"type"`
	Properties map[string]Schema `yaml:"properties,omitempty"`
	Required   []string          `yaml:"required,omitempty"`
	Items      *Schema           `yaml:"items,omitempty"`
	Ref        string            `yaml:"$ref,omitempty"`
}

Schema represents a simplified OpenAPI schema

Jump to

Keyboard shortcuts

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