http

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2025 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// XForwardedFor is the header key for the X-Forwarded-For header
	XForwardedFor = "X-Forwarded-For"

	// Authorization is the header key for the Authorization header
	Authorization = "Authorization"
)
View Source
const (
	ErrInvalidRequestBody = "invalid request body type, expected: %v"
	ErrNilSubmodule       = "%s: submodule at index %d is nil"
)

Variables

View Source
var (
	ErrCookieNotFound = errors.New("cookie not found")
	ErrNilRequestBody = errors.New("request body cannot be nil")
	ErrInDevelopment  = errors.New("in development")
	ErrNilModule      = errors.New("module cannot be nil")
)
View Source
var (
	ErrBadRequest          = errors.New(BadRequest)
	ErrInternalServerError = errors.New(InternalServerError)
	ErrServiceUnavailable  = errors.New(ServiceUnavailable)
	ErrUnauthorized        = errors.New(Unauthorized)
	ErrNotImplemented      = errors.New(NotImplemented)
	ErrTooManyRequests     = errors.New(TooManyRequests)
	ErrRequestTimeout      = errors.New(RequestTimeout)
	ErrNotFound            = errors.New(NotFound)
	ErrUnauthenticated     = errors.New("missing or invalid bearer token on authentication header")
)
View Source
var (
	ErrCodeCookieNotFound string
)

Functions

func GetClientIP added in v0.5.8

func GetClientIP(r *http.Request) string

GetClientIP returns the client's IP address from the request

It checks the X-Forwarded-For header first (in case of proxies or load balancers), and falls back to the RemoteAddr if the header is not present.

Parameters:

  • r: The HTTP request

Returns:

  • string: The client's IP address

func NewMiddlewares added in v0.7.8

func NewMiddlewares(middlewares ...func(next http.Handler) http.Handler) []func(next http.Handler) http.Handler

NewMiddlewares is a function that creates a new middlewares slice

Usage: NewMiddlewares(middleware1, middleware2, ...)

Parameters:

  • middlewares: variadic list of middleware functions

Returns:

  • []func(next http.ResponsesHandler) http.ResponsesHandler: Slice of middleware functions

Types

type Module added in v0.6.24

type Module struct {
	Pattern       string
	BeforeLoadFn  func(m *Module)
	AddHandlersFn func(m *Module)
	AfterLoadFn   func(m *Module)
	Middlewares   []func(next http.Handler) http.Handler
	Submodules    []*Module
	gonethttproute.RouterWrapper
}

Module is the struct for the route module

func NewSubmodules added in v0.6.24

func NewSubmodules(submodules ...*Module) []*Module

NewSubmodules is a function that creates a new submodules slice

Usage: NewSubmodules(submodule1, submodule2, ...)

Parameters:

  • submodules: variadic list of submodule pointers

Returns:

  • []*Module: Slice of submodule pointers

func (*Module) Create added in v0.6.24

func (m *Module) Create(
	baseRouter gonethttproute.RouterWrapper,
) error

Create is a function that creates the router for the controller and its submodules, and loads the module

Parameters:

  • baseRouter: The base router to create the module's router group

Returns:

  • error: The error if any

func (*Module) GetRouter added in v0.6.24

func (m *Module) GetRouter() gonethttproute.RouterWrapper

GetRouter returns the router

Returns:

  • gonethttproute.RouterWrapper: The router

Jump to

Keyboard shortcuts

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