Documentation
¶
Index ¶
- Constants
- func StatusText(code int) string
- type Context
- type CorsOptions
- type Handler
- type Option
- func WithAddr(addr string) Option
- func WithBodyLimit(bodyLimit int) Option
- func WithCaseSensitive(enable bool) Option
- func WithConcurrency(concurrency int) Option
- func WithConsole(enable bool) Option
- func WithCorsOptions(corsOpts CorsOptions) Option
- func WithCredentials(certFile, keyFile string) Option
- func WithDisableDefaultContentType(disable bool) Option
- func WithDisableDefaultDate(disable bool) Option
- func WithDisableHeadAutoRegister(disable bool) Option
- func WithDisableHeaderNormalizing(disable bool) Option
- func WithDisableKeepalive(disable bool) Option
- func WithDisablePreParseMultipartForm(disable bool) Option
- func WithEnableIPValidation(enable bool) Option
- func WithEnableSplittingOnParsers(enable bool) Option
- func WithErrorHandler(errorHandler fiber.ErrorHandler) Option
- func WithImmutable(enable bool) Option
- func WithMiddlewares(middlewares ...any) Option
- func WithName(name string) Option
- func WithPassLocalsToViews(enable bool) Option
- func WithProxyOptions(proxyOpts ProxyOptions) Option
- func WithReadBufferSize(size int) Option
- func WithReduceMemoryUsage(enable bool) Option
- func WithRegistry(r registry.Registry) Option
- func WithStreamRequestBody(enable bool) Option
- func WithStrictRouting(enable bool) Option
- func WithSwagOptions(swagOpts SwagOptions) Option
- func WithTransporter(transporter transport.Transporter) Option
- func WithUnescapePath(enable bool) Option
- func WithViews(views fiber.Views) Option
- func WithViewsLayout(layout string) Option
- func WithWriteBufferSize(size int) Option
- type Proxy
- type ProxyOptions
- type Resp
- type Router
- type Server
- type SwagOptions
- type TrustProxyOptions
Constants ¶
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 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 StatusInternalServerError = http.StatusInternalServerError // RFC 9110, 15.6.1 StatusNotImplemented = http.StatusNotImplemented // RFC 9110, 15.6.2 StatusBadGateway = http.StatusBadGateway // RFC 9110, 15.6.3 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 ¶
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 Option ¶
type Option func(o *options)
Option is an HTTP server configuration function.
func WithBodyLimit ¶
WithBodyLimit sets the body size limit.
func WithCaseSensitive ¶
WithCaseSensitive sets whether route matching is case sensitive.
func WithConcurrency ¶
WithConcurrency sets the maximum number of concurrent connections.
func WithConsole ¶
WithConsole sets whether console output is enabled.
func WithCorsOptions ¶
func WithCorsOptions(corsOpts CorsOptions) Option
WithCorsOptions sets the CORS configuration.
func WithCredentials ¶
WithCredentials sets the certificate and key files.
func WithDisableDefaultContentType ¶
WithDisableDefaultContentType sets whether the default Content-Type is disabled.
func WithDisableDefaultDate ¶
WithDisableDefaultDate sets whether the default date header is disabled.
func WithDisableHeadAutoRegister ¶
WithDisableHeadAutoRegister sets whether automatic HEAD registration is disabled.
func WithDisableHeaderNormalizing ¶
WithDisableHeaderNormalizing sets whether default header normalization is disabled.
func WithDisableKeepalive ¶
WithDisableKeepalive sets whether keepalive is disabled.
func WithDisablePreParseMultipartForm ¶
WithDisablePreParseMultipartForm sets whether pre-parsing of multipart/form-data is disabled.
func WithEnableIPValidation ¶
WithEnableIPValidation sets whether IP validation is enabled.
func WithEnableSplittingOnParsers ¶
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 ¶
WithImmutable sets whether immutable routing is enabled.
func WithMiddlewares ¶
WithMiddlewares sets the middlewares.
func WithPassLocalsToViews ¶
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 ¶
WithReadBufferSize sets the read buffer size.
func WithReduceMemoryUsage ¶
WithReduceMemoryUsage sets whether memory usage is reduced.
func WithRegistry ¶
WithRegistry sets the service registry.
func WithStreamRequestBody ¶
WithStreamRequestBody sets whether the request body is streamed.
func WithStrictRouting ¶
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 ¶
WithUnescapePath sets whether path parameters are unescaped.
func WithViewsLayout ¶
WithViewsLayout sets the view layout.
func WithWriteBufferSize ¶
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) NewMeshClient ¶
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
type ProxyOptions ¶
type ProxyOptions struct {
ProxyHeader string `json:"proxyHeader"` // Proxy header; defaults to X-Forwarded-For
TrustProxy TrustProxyOptions `json:"trustProxy"` // Trusted proxy configuration
}
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:
- due.Handler
fiber-style route handlers:
- fiber.Handler
- func(fiber.Ctx)
express-style route handlers:
- func(fiber.Req, fiber.Res) error
- func(fiber.Req, fiber.Res)
- func(fiber.Req, fiber.Res, func() error) error
- func(fiber.Req, fiber.Res, func() error)
- func(fiber.Req, fiber.Res, func()) error
- func(fiber.Req, fiber.Res, func())
- func(fiber.Req, fiber.Res, func(error))
- func(fiber.Req, fiber.Res, func(error)) error
- func(fiber.Req, fiber.Res, func(error) error)
- func(fiber.Req, fiber.Res, func(error) error) error
net/http-style route handlers:
- http.HandlerFunc
- http.Handler
- func(http.ResponseWriter, *http.Request)
fasthttp-style route handlers:
- fasthttp.RequestHandler
- func(*fasthttp.RequestCtx) error
type Server ¶
Server is the HTTP server component.
It is built on top of the fiber framework and supports route registration, middleware, CORS, Swagger and more.
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)
}