http

package module
v2.0.0-...-715e587 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 21 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

Types

type Context

type Context interface {
	fiber.Ctx
	// CTX 获取fiber.Ctx
	CTX() fiber.Ctx
	// Proxy 获取代理API
	Proxy() *Proxy
	// Failure 失败响应
	Failure(rst any) error
	// Success 成功响应
	Success(data ...any) error
	// StdRequest 获取标准请求(net/http)
	StdRequest() *http.Request
}

type CorsOptions

type CorsOptions struct {
	Enable              bool     `json:"enable"`              // 是否启用
	AllowOrigins        []string `json:"allowOrigins"`        // 允许跨域的请求源。默认为[],即为允许所有请求源
	AllowMethods        []string `json:"allowMethods"`        // 允许跨域的请求方法。默认为["GET", "POST", "HEAD", "PUT", "DELETE", "PATCH"]
	AllowHeaders        []string `json:"allowHeaders"`        // 允许跨域的请求头部。默认为[],即为允许所有请求头部
	AllowCredentials    bool     `json:"allowCredentials"`    // 当允许所有源时,根据CORS规范不允许携带凭据。默认为false
	ExposeHeaders       []string `json:"exposeHeaders"`       // 允许暴露给客户端的头部。默认为[],即为允许暴露所有头部
	MaxAge              int      `json:"maxAge"`              // 浏览器缓存预检请求结果的时间。默认为0
	AllowPrivateNetwork bool     `json:"allowPrivateNetwork"` // 是否允许来自私有网络的请求。设置为true时,响应头Access-Control-Allow-Private-Network会被设置为true。默认为false
}

type Handler

type Handler = func(ctx Context) error

type Option

type Option func(o *options)

func WithAddr

func WithAddr(addr string) Option

WithAddr 设置监听地址

func WithBodyLimit

func WithBodyLimit(bodyLimit int) Option

WithBodyLimit 设置body大小

func WithCaseSensitive

func WithCaseSensitive(enable bool) Option

WithCaseSensitive 设置是否区分路由大小写

func WithConcurrency

func WithConcurrency(concurrency int) Option

WithConcurrency 设置最大并发连接数

func WithConsole

func WithConsole(enable bool) Option

WithConsole 设置是否启用控制台输出

func WithCorsOptions

func WithCorsOptions(corsOpts CorsOptions) Option

WithCorsOptions 设置跨域配置

func WithCredentials

func WithCredentials(certFile, keyFile string) Option

WithCredentials 设置证书和秘钥

func WithDisableDefaultContentType

func WithDisableDefaultContentType(disable bool) Option

WithDisableDefaultContentType 设置是否禁用默认Content-Type

func WithDisableDefaultDate

func WithDisableDefaultDate(disable bool) Option

WithDisableDefaultDate 设置是否禁用默认日期

func WithDisableHeadAutoRegister

func WithDisableHeadAutoRegister(disable bool) Option

WithDisableHeadAutoRegister 设置是否禁用HEAD自动注册

func WithDisableHeaderNormalizing

func WithDisableHeaderNormalizing(disable bool) Option

WithDisableHeaderNormalizing 设置是否禁用默认头部归一化

func WithDisableKeepalive

func WithDisableKeepalive(disable bool) Option

WithDisableKeepalive 设置是否禁用keepalive

func WithDisablePreParseMultipartForm

func WithDisablePreParseMultipartForm(disable bool) Option

WithDisablePreParseMultipartForm 设置是否禁用预解析multipart/form-data

func WithEnableIPValidation

func WithEnableIPValidation(enable bool) Option

WithEnableIPValidation 设置是否启用IP验证

func WithEnableSplittingOnParsers

func WithEnableSplittingOnParsers(enable bool) Option

WithEnableSplittingOnParsers 设置是否在解析器上拆分请求体

func WithErrorHandler

func WithErrorHandler(errorHandler fiber.ErrorHandler) Option

WithErrorHandler 设置错误处理函数

func WithImmutable

func WithImmutable(enable bool) Option

WithImmutable 设置是否启用不可变路由

func WithMiddlewares

func WithMiddlewares(middlewares ...any) Option

WithMiddlewares 设置中间件

func WithName

func WithName(name string) Option

WithName 设置实例名称

func WithPassLocalsToViews

func WithPassLocalsToViews(enable bool) Option

WithPassLocalsToViews 设置是否将上下文 locals 传递给视图引擎

func WithProxyHeader

func WithProxyHeader(proxyHeader string) Option

WithProxyHeader 设置代理头部

func WithReadBufferSize

func WithReadBufferSize(size int) Option

WithReadBufferSize 设置读取缓冲区大小

func WithReduceMemoryUsage

func WithReduceMemoryUsage(enable bool) Option

WithReduceMemoryUsage 设置是否减少内存占用

func WithRegistry

func WithRegistry(r registry.Registry) Option

WithRegistry 设置服务注册器

func WithStreamRequestBody

func WithStreamRequestBody(enable bool) Option

WithStreamRequestBody 设置是否流式请求体

func WithStrictRouting

func WithStrictRouting(enable bool) Option

WithStrictRouting 设置是否启用严格路由模式

func WithSwagOptions

func WithSwagOptions(swagOpts SwagOptions) Option

WithSwagOptions 设置swagger配置

func WithTransporter

func WithTransporter(transporter transport.Transporter) Option

WithTransporter 设置消息传输器

func WithTrustProxy

func WithTrustProxy(enable bool) Option

WithTrustProxy 设置是否信任代理

func WithTrustProxyConfig

func WithTrustProxyConfig(trustProxyConfig TrustProxyOptions) Option

WithTrustProxyConfig 设置信任代理配置

func WithUnescapePath

func WithUnescapePath(enable bool) Option

WithUnescapePath 设置是否unescape路径参数

func WithViews

func WithViews(views fiber.Views) Option

WithViews 设置视图引擎

func WithViewsLayout

func WithViewsLayout(layout string) Option

WithViewsLayout 设置视图布局

func WithWriteBufferSize

func WithWriteBufferSize(size int) Option

WithWriteBufferSize 设置写入缓冲区大小

type Proxy

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

func (*Proxy) App

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

App 获取fiber原生应用

func (*Proxy) NewMeshClient

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

NewMeshClient 新建微服务客户端 target参数可分为三种模式: 服务直连模式: direct://127.0.0.1:8011 服务直连模式: direct://711baf8d-8a06-11ef-b7df-f4f19e1f0070 服务发现模式: discovery://service_name

func (*Proxy) Router

func (p *Proxy) Router() Router

Router 获取路由器

type Resp

type Resp struct {
	Code    int    `json:"code"`              // 响应码
	Message string `json:"message"`           // 响应消息
	Details string `json:"details,omitempty"` // 响应详情
	Data    any    `json:"data,omitempty"`    // 响应数据
}

type Router

type Router interface {
	// Get 添加GET请求处理器
	Get(path string, handlers ...any) Router
	// Post 添加POST请求处理器
	Post(path string, handlers ...any) Router
	// Head 添加HEAD请求处理器
	Head(path string, handlers ...any) Router
	// Put 添加PUT请求处理器
	Put(path string, handlers ...any) Router
	// Delete 添加DELETE请求处理器
	Delete(path string, handlers ...any) Router
	// Connect 添加CONNECT请求处理器
	Connect(path string, handlers ...any) Router
	// Options 添加OPTIONS请求处理器
	Options(path string, handlers ...any) Router
	// Trace 添加TRACE请求处理器
	Trace(path string, handlers ...any) Router
	// Patch 添加PATCH请求处理器
	Patch(path string, handlers ...any) Router
	// Add 添加路由处理器
	Add(methods []string, path string, handlers ...any) Router
	// Group 路由组
	Group(prefix string, middlewares ...any) Router
}

type Server

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

func NewServer

func NewServer(opts ...Option) *Server

func (*Server) Init

func (s *Server) Init()

Init 初始化组件

func (*Server) Name

func (s *Server) Name() string

Name 组件名称

func (*Server) Proxy

func (s *Server) Proxy() *Proxy

Proxy 获取HTTP代理API

func (*Server) Start

func (s *Server) Start()

Start 启动组件

type SwagOptions

type SwagOptions struct {
	Enable           bool   `json:"enable"`           // 是否启用
	Title            string `json:"title"`            // 文档标题
	FilePath         string `json:"filePath"`         // 文档路径
	BasePath         string `json:"basePath"`         // 访问路径
	SwaggerBundleUrl string `json:"swaggerBundleUrl"` // swagger-ui-bundle.js地址
	SwaggerPresetUrl string `json:"swaggerPresetUrl"` // swagger-ui-standalone-preset.js地址
	SwaggerStylesUrl string `json:"swaggerStylesUrl"` // swagger-ui.css地址
}

type TrustProxyOptions

type TrustProxyOptions struct {
	Proxies   []string `json:"proxies"`   // 代理是受信任代理 IP 地址或 CIDR 范围的列表
	LinkLocal bool     `json:"linkLocal"` // 支持信任所有链路本地 IP 范围(例如 169.254.0.0/16、fe80::/10)
	Loopback  bool     `json:"loopback"`  // 支持信任所有环回 IP 范围(例如 127.0.0.0/8、::1/128)
	Private   bool     `json:"private"`   // 支持信任所有私有 IP 范围(例如 10.0.0.0/8、172.16.0.0/12、192.168.0.0/16、fc00::/7)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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