Help us shape the future of Go! Take the 2026 Go Developer Survey

http

package module
v2.0.0-...-1948240 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 25 Imported by: 5

Documentation

Index

Constants

View Source
const (
	StatusContinue           = http.StatusContinue           // RFC 9110, 15.2.1
	StatusSwitchingProtocols = http.StatusSwitchingProtocols // RFC 9110, 15.2.2
	StatusProcessing         = http.StatusProcessing         // RFC 2518, 10.1
	StatusEarlyHints         = http.StatusEarlyHints         // RFC 8297

	StatusOK                   = http.StatusOK                   // RFC 9110, 15.3.1
	StatusCreated              = http.StatusCreated              // RFC 9110, 15.3.2
	StatusAccepted             = http.StatusAccepted             // RFC 9110, 15.3.3
	StatusNonAuthoritativeInfo = http.StatusNonAuthoritativeInfo // RFC 9110, 15.3.4
	StatusNoContent            = http.StatusNoContent            // RFC 9110, 15.3.5
	StatusResetContent         = http.StatusResetContent         // RFC 9110, 15.3.6
	StatusPartialContent       = http.StatusPartialContent       // RFC 9110, 15.3.7
	StatusMultiStatus          = http.StatusMultiStatus          // RFC 4918, 11.1
	StatusAlreadyReported      = http.StatusAlreadyReported      // RFC 5842, 7.1
	StatusIMUsed               = http.StatusIMUsed               // RFC 3229, 10.4.1

	StatusMultipleChoices   = http.StatusMultipleChoices   // RFC 9110, 15.4.1
	StatusMovedPermanently  = http.StatusMovedPermanently  // RFC 9110, 15.4.2
	StatusFound             = http.StatusFound             // RFC 9110, 15.4.3
	StatusSeeOther          = http.StatusSeeOther          // RFC 9110, 15.4.4
	StatusNotModified       = http.StatusNotModified       // RFC 9110, 15.4.5
	StatusUseProxy          = http.StatusUseProxy          // RFC 9110, 15.4.6
	StatusTemporaryRedirect = http.StatusTemporaryRedirect // RFC 9110, 15.4.8
	StatusPermanentRedirect = http.StatusPermanentRedirect // RFC 9110, 15.4.9

	StatusBadRequest                   = http.StatusBadRequest                   // RFC 9110, 15.5.1
	StatusUnauthorized                 = http.StatusUnauthorized                 // RFC 9110, 15.5.2
	StatusPaymentRequired              = http.StatusPaymentRequired              // RFC 9110, 15.5.3
	StatusForbidden                    = http.StatusForbidden                    // RFC 9110, 15.5.4
	StatusNotFound                     = http.StatusNotFound                     // RFC 9110, 15.5.5
	StatusMethodNotAllowed             = http.StatusMethodNotAllowed             // RFC 9110, 15.5.6
	StatusNotAcceptable                = http.StatusNotAcceptable                // RFC 9110, 15.5.7
	StatusProxyAuthRequired            = http.StatusProxyAuthRequired            // RFC 9110, 15.5.8
	StatusRequestTimeout               = http.StatusRequestTimeout               // RFC 9110, 15.5.9
	StatusConflict                     = http.StatusConflict                     // RFC 9110, 15.5.10
	StatusGone                         = http.StatusGone                         // RFC 9110, 15.5.11
	StatusLengthRequired               = http.StatusLengthRequired               // RFC 9110, 15.5.12
	StatusPreconditionFailed           = http.StatusPreconditionFailed           // RFC 9110, 15.5.13
	StatusRequestEntityTooLarge        = http.StatusRequestEntityTooLarge        // RFC 9110, 15.5.14
	StatusRequestURITooLong            = http.StatusRequestURITooLong            // RFC 9110, 15.5.15
	StatusUnsupportedMediaType         = http.StatusUnsupportedMediaType         // RFC 9110, 15.5.16
	StatusRequestedRangeNotSatisfiable = http.StatusRequestedRangeNotSatisfiable // RFC 9110, 15.5.17
	StatusExpectationFailed            = http.StatusExpectationFailed            // RFC 9110, 15.5.18
	StatusTeapot                       = http.StatusTeapot                       // RFC 9110, 15.5.19 (Unused)
	StatusMisdirectedRequest           = http.StatusMisdirectedRequest           // RFC 9110, 15.5.20
	StatusUnprocessableEntity          = http.StatusUnprocessableEntity          // RFC 9110, 15.5.21
	StatusLocked                       = http.StatusLocked                       // RFC 4918, 11.3
	StatusFailedDependency             = http.StatusFailedDependency             // RFC 4918, 11.4
	StatusTooEarly                     = http.StatusTooEarly                     // RFC 8470, 5.2.
	StatusUpgradeRequired              = http.StatusUpgradeRequired              // RFC 9110, 15.5.22
	StatusPreconditionRequired         = http.StatusPreconditionRequired         // RFC 6585, 3
	StatusTooManyRequests              = http.StatusTooManyRequests              // RFC 6585, 4
	StatusRequestHeaderFieldsTooLarge  = http.StatusRequestHeaderFieldsTooLarge  // RFC 6585, 5
	StatusUnavailableForLegalReasons   = http.StatusUnavailableForLegalReasons   // RFC 7725, 3

	StatusInternalServerError           = http.StatusInternalServerError           // RFC 9110, 15.6.1
	StatusNotImplemented                = http.StatusNotImplemented                // RFC 9110, 15.6.2
	StatusBadGateway                    = http.StatusBadGateway                    // RFC 9110, 15.6.3
	StatusServiceUnavailable            = http.StatusServiceUnavailable            // RFC 9110, 15.6.4
	StatusGatewayTimeout                = http.StatusGatewayTimeout                // RFC 9110, 15.6.5
	StatusHTTPVersionNotSupported       = http.StatusHTTPVersionNotSupported       // RFC 9110, 15.6.6
	StatusVariantAlsoNegotiates         = http.StatusVariantAlsoNegotiates         // RFC 2295, 8.1
	StatusInsufficientStorage           = http.StatusInsufficientStorage           // RFC 4918, 11.5
	StatusLoopDetected                  = http.StatusLoopDetected                  // RFC 5842, 7.2
	StatusNotExtended                   = http.StatusNotExtended                   // RFC 2774, 7
	StatusNetworkAuthenticationRequired = http.StatusNetworkAuthenticationRequired // RFC 6585, 6
)

Variables

This section is empty.

Functions

func StatusText

func StatusText(code int) string

StatusText returns the text for the given HTTP status code.

Types

type Context

type Context interface {
	fiber.Ctx
	// CTX returns the underlying [fiber.Ctx].
	CTX() fiber.Ctx
	// Proxy returns the proxy API.
	Proxy() *Proxy
	// Failure writes a failure response.
	Failure(rst any) error
	// Success writes a success response.
	Success(data ...any) error
	// StdRequest returns the equivalent [http.Request] (net/http).
	StdRequest() *http.Request
}

Context is the HTTP context interface.

It extends fiber.Ctx with a proxy API, response handling and a standard request.

type CorsOptions

type CorsOptions struct {
	Enable              bool     `json:"enable"`              // Whether CORS is enabled
	AllowOrigins        []string `json:"allowOrigins"`        // Allowed request origins. Defaults to [], which allows every origin
	AllowMethods        []string `json:"allowMethods"`        // Allowed request methods. Defaults to ["GET", "POST", "HEAD", "PUT", "DELETE", "PATCH"]
	AllowHeaders        []string `json:"allowHeaders"`        // Allowed request headers. Defaults to [], which allows every header
	AllowCredentials    bool     `json:"allowCredentials"`    // When every origin is allowed, credentials are not permitted by the CORS specification. Defaults to false
	ExposeHeaders       []string `json:"exposeHeaders"`       // Headers exposed to the client. Defaults to [], which exposes every header
	MaxAge              int      `json:"maxAge"`              // Time for which the browser caches the preflight request result. Defaults to 0
	AllowPrivateNetwork bool     `json:"allowPrivateNetwork"` // Whether requests from private networks are allowed. When true, the Access-Control-Allow-Private-Network response header is set to true. Defaults to false
}

type Handler

type Handler = func(ctx Context) error

type Option

type Option func(o *options)

Option is an HTTP server configuration function.

func WithAddr

func WithAddr(addr string) Option

WithAddr sets the listen address.

func WithBodyLimit

func WithBodyLimit(bodyLimit int) Option

WithBodyLimit sets the body size limit.

func WithCaseSensitive

func WithCaseSensitive(enable bool) Option

WithCaseSensitive sets whether route matching is case sensitive.

func WithConcurrency

func WithConcurrency(concurrency int) Option

WithConcurrency sets the maximum number of concurrent connections.

func WithConsole

func WithConsole(enable bool) Option

WithConsole sets whether console output is enabled.

func WithCorsOptions

func WithCorsOptions(corsOpts CorsOptions) Option

WithCorsOptions sets the CORS configuration.

func WithCredentials

func WithCredentials(certFile, keyFile string) Option

WithCredentials sets the certificate and key files.

func WithDisableDefaultContentType

func WithDisableDefaultContentType(disable bool) Option

WithDisableDefaultContentType sets whether the default Content-Type is disabled.

func WithDisableDefaultDate

func WithDisableDefaultDate(disable bool) Option

WithDisableDefaultDate sets whether the default date header is disabled.

func WithDisableHeadAutoRegister

func WithDisableHeadAutoRegister(disable bool) Option

WithDisableHeadAutoRegister sets whether automatic HEAD registration is disabled.

func WithDisableHeaderNormalizing

func WithDisableHeaderNormalizing(disable bool) Option

WithDisableHeaderNormalizing sets whether default header normalization is disabled.

func WithDisableKeepalive

func WithDisableKeepalive(disable bool) Option

WithDisableKeepalive sets whether keepalive is disabled.

func WithDisablePreParseMultipartForm

func WithDisablePreParseMultipartForm(disable bool) Option

WithDisablePreParseMultipartForm sets whether pre-parsing of multipart/form-data is disabled.

func WithEnableIPValidation

func WithEnableIPValidation(enable bool) Option

WithEnableIPValidation sets whether IP validation is enabled.

func WithEnableSplittingOnParsers

func WithEnableSplittingOnParsers(enable bool) Option

WithEnableSplittingOnParsers sets whether splitting the request body on parsers is enabled.

func WithErrorHandler

func WithErrorHandler(errorHandler fiber.ErrorHandler) Option

WithErrorHandler sets the error handler.

func WithImmutable

func WithImmutable(enable bool) Option

WithImmutable sets whether immutable routing is enabled.

func WithMiddlewares

func WithMiddlewares(middlewares ...any) Option

WithMiddlewares sets the middlewares.

func WithName

func WithName(name string) Option

WithName sets the instance name.

func WithPassLocalsToViews

func WithPassLocalsToViews(enable bool) Option

WithPassLocalsToViews sets whether context locals are passed to the view engine.

func WithProxyOptions

func WithProxyOptions(proxyOpts ProxyOptions) Option

WithProxyOptions sets the proxy configuration.

func WithReadBufferSize

func WithReadBufferSize(size int) Option

WithReadBufferSize sets the read buffer size.

func WithReduceMemoryUsage

func WithReduceMemoryUsage(enable bool) Option

WithReduceMemoryUsage sets whether memory usage is reduced.

func WithRegistry

func WithRegistry(r registry.Registry) Option

WithRegistry sets the service registry.

func WithStreamRequestBody

func WithStreamRequestBody(enable bool) Option

WithStreamRequestBody sets whether the request body is streamed.

func WithStrictRouting

func WithStrictRouting(enable bool) Option

WithStrictRouting sets whether strict routing is enabled.

func WithSwagOptions

func WithSwagOptions(swagOpts SwagOptions) Option

WithSwagOptions sets the Swagger configuration.

func WithTransporter

func WithTransporter(transporter transport.Transporter) Option

WithTransporter sets the message transporter.

func WithUnescapePath

func WithUnescapePath(enable bool) Option

WithUnescapePath sets whether path parameters are unescaped.

func WithViews

func WithViews(views fiber.Views) Option

WithViews sets the view engine.

func WithViewsLayout

func WithViewsLayout(layout string) Option

WithViewsLayout sets the view layout.

func WithWriteBufferSize

func WithWriteBufferSize(size int) Option

WithWriteBufferSize sets the write buffer size.

type Proxy

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

Proxy is the HTTP proxy.

It exposes the full set of features that an HTTP Server provides to the outside.

func (*Proxy) App

func (p *Proxy) App() *fiber.App

App returns the underlying fiber application.

func (*Proxy) NewMeshClient

func (p *Proxy) NewMeshClient(target string) (transport.Client, error)

NewMeshClient creates a mesh client. The target may take one of three forms:

  • direct connection: direct://127.0.0.1:8011
  • direct connection: direct://711baf8d-8a06-11ef-b7df-f4f19e1f0070
  • service discovery: discovery://service_name

func (*Proxy) Router

func (p *Proxy) Router() Router

Router returns the router.

type ProxyOptions

type ProxyOptions struct {
	ProxyHeader string            `json:"proxyHeader"` // Proxy header; defaults to X-Forwarded-For
	TrustProxy  TrustProxyOptions `json:"trustProxy"`  // Trusted proxy configuration
}

type Resp

type Resp struct {
	Code    int    `json:"code"`              // Response code
	Message string `json:"message"`           // Response message
	Details string `json:"details,omitempty"` // Response details
	Data    any    `json:"data,omitempty"`    // Response data
}

type Router

type Router interface {
	// Get registers a handler for GET requests.
	Get(path string, handlers ...any) Router
	// Post registers a handler for POST requests.
	Post(path string, handlers ...any) Router
	// Head registers a handler for HEAD requests.
	Head(path string, handlers ...any) Router
	// Put registers a handler for PUT requests.
	Put(path string, handlers ...any) Router
	// Delete registers a handler for DELETE requests.
	Delete(path string, handlers ...any) Router
	// Connect registers a handler for CONNECT requests.
	Connect(path string, handlers ...any) Router
	// Options registers a handler for OPTIONS requests.
	Options(path string, handlers ...any) Router
	// Trace registers a handler for TRACE requests.
	Trace(path string, handlers ...any) Router
	// Patch registers a handler for PATCH requests.
	Patch(path string, handlers ...any) Router
	// All registers a handler for every method.
	All(path string, handlers ...any) Router
	// Add registers route handlers for the given methods.
	Add(methods []string, path string, handlers ...any) Router
	// Group returns a route group.
	Group(prefix string, middlewares ...any) Router
}

Router accepts the following forms of route registration.

due-style route handlers:

  1. due.Handler

fiber-style route handlers:

  1. fiber.Handler
  2. func(fiber.Ctx)

express-style route handlers:

  1. func(fiber.Req, fiber.Res) error
  2. func(fiber.Req, fiber.Res)
  3. func(fiber.Req, fiber.Res, func() error) error
  4. func(fiber.Req, fiber.Res, func() error)
  5. func(fiber.Req, fiber.Res, func()) error
  6. func(fiber.Req, fiber.Res, func())
  7. func(fiber.Req, fiber.Res, func(error))
  8. func(fiber.Req, fiber.Res, func(error)) error
  9. func(fiber.Req, fiber.Res, func(error) error)
  10. func(fiber.Req, fiber.Res, func(error) error) error

net/http-style route handlers:

  1. http.HandlerFunc
  2. http.Handler
  3. func(http.ResponseWriter, *http.Request)

fasthttp-style route handlers:

  1. fasthttp.RequestHandler
  2. func(*fasthttp.RequestCtx) error

type Server

type Server struct {
	component.Base
	// contains filtered or unexported fields
}

Server is the HTTP server component.

It is built on top of the fiber framework and supports route registration, middleware, CORS, Swagger and more.

func NewServer

func NewServer(opts ...Option) *Server

func (*Server) Destroy

func (s *Server) Destroy()

Destroy destroys the component.

func (*Server) Init

func (s *Server) Init()

Init initializes the component.

func (*Server) Name

func (s *Server) Name() string

Name returns the component name.

func (*Server) Proxy

func (s *Server) Proxy() *Proxy

Proxy returns the HTTP proxy API.

func (*Server) Start

func (s *Server) Start()

Start starts the component.

type SwagOptions

type SwagOptions struct {
	Enable           bool   `json:"enable"`           // Whether Swagger is enabled
	Title            string `json:"title"`            // Document title
	FilePath         string `json:"filePath"`         // Document path
	BasePath         string `json:"basePath"`         // Access path
	SwaggerBundleUrl string `json:"swaggerBundleUrl"` // swagger-ui-bundle.js URL
	SwaggerPresetUrl string `json:"swaggerPresetUrl"` // swagger-ui-standalone-preset.js URL
	SwaggerStylesUrl string `json:"swaggerStylesUrl"` // swagger-ui.css URL
}

type TrustProxyOptions

type TrustProxyOptions struct {
	Enable    bool     `json:"enable"`    // Whether it is enabled; defaults to false
	Proxies   []string `json:"proxies"`   // Proxies is the list of trusted proxy IP addresses or CIDR ranges
	LinkLocal bool     `json:"linkLocal"` // Whether all link-local IP ranges are trusted (for example 169.254.0.0/16, fe80::/10)
	Loopback  bool     `json:"loopback"`  // Whether all loopback IP ranges are trusted (for example 127.0.0.0/8, ::1/128)
	Private   bool     `json:"private"`   // Whether all private IP ranges are trusted (for example 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, fc00::/7)
}

Directories

Path Synopsis
middleware

Jump to

Keyboard shortcuts

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