common

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIKeyMiddleware

func APIKeyMiddleware() gin.HandlerFunc

APIKeyMiddleware validates API keys for public routes

func GetAPIKeyUserID

func GetAPIKeyUserID(c *gin.Context) int

GetAPIKeyUserID extracts the API key user ID from the context

func GetPaginationParams

func GetPaginationParams(c *gin.Context) (int, int)

GetPaginationParams extracts and validates pagination parameters

func GetUserID

func GetUserID(c *gin.Context) int

GetUserID extracts the authenticated user ID from the context

func RespondWithError

func RespondWithError(c *gin.Context, statusCode int, message string, err error)

RespondWithError sends a standardized error response

func RespondWithErrorMessage

func RespondWithErrorMessage(c *gin.Context, statusCode int, message string)

RespondWithErrorMessage is a simplified version of the error response function that only takes a message without an error object

func RespondWithSuccess

func RespondWithSuccess(c *gin.Context, statusCode int, data interface{})

RespondWithSuccess sends a standardized success response

Types

type APIKey

type APIKey struct {
	UserID int
	Key    string
}

APIKey represents a simple API key for public API access

type ErrorResponse

type ErrorResponse struct {
	Error   string `json:"error"`
	Message string `json:"message,omitempty"`
}

ErrorResponse is a standardized error response

type SuccessResponse

type SuccessResponse struct {
	Success bool        `json:"success"`
	Data    interface{} `json:"data,omitempty"`
}

SuccessResponse is a standardized success response with data

Jump to

Keyboard shortcuts

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