middleware

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const RequestIDKey = "requestID"

RequestIDKey is the key used to store the request ID in the context

Variables

This section is empty.

Functions

func GenerateUUID

func GenerateUUID() string

GenerateUUID generates a random UUID

func GetError

func GetError(r *http.Request) error

func GetHandlerResponse

func GetHandlerResponse(r *http.Request) interface{}

func HandlerResponse

func HandlerResponse(next http.Handler) http.Handler

HandlerResponse is the middleware function for handling response and errors

func RequestID

func RequestID(logger *slog.Logger) mux.MiddlewareFunc

RequestID is a middleware that adds a unique request id to the request context

func RequestLog

func RequestLog(logger *slog.Logger) mux.MiddlewareFunc

RequestLog is a middleware that logs request details

func SetError

func SetError(r *http.Request, err error)

func SetHandlerResponse

func SetHandlerResponse(r *http.Request, response interface{})

Types

type DefaultHandlerResponse

type DefaultHandlerResponse struct {
	Code    int         `json:"code"    dc:"Error code"`
	Message string      `json:"message" dc:"Error message"`
	Data    interface{} `json:"data"    dc:"Result data for certain request according API definition"`
}

DefaultHandlerResponse is the default implementation of HandlerResponse.

Jump to

Keyboard shortcuts

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