SpringWeb

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2020 License: Apache-2.0 Imports: 19 Imported by: 15

README

spring-web

Documentation

Index

Constants

View Source
const (
	HeaderContentDisposition = "Content-Disposition"
	HeaderContentType        = "Content-Type"
	HeaderXForwardedProto    = "X-Forwarded-Proto"
	HeaderXForwardedProtocol = "X-Forwarded-Protocol"
	HeaderXForwardedSsl      = "X-Forwarded-Ssl"
	HeaderXUrlScheme         = "X-Url-Scheme"

	CharsetUTF8 = "charset=UTF-8"

	MIMEApplicationJSON                  = "application/json"
	MIMEApplicationJSONCharsetUTF8       = MIMEApplicationJSON + "; " + CharsetUTF8
	MIMEApplicationJavaScript            = "application/javascript"
	MIMEApplicationJavaScriptCharsetUTF8 = MIMEApplicationJavaScript + "; " + CharsetUTF8
	MIMEApplicationXML                   = "application/xml"
	MIMEApplicationXMLCharsetUTF8        = MIMEApplicationXML + "; " + CharsetUTF8
	MIMETextXML                          = "text/xml"
	MIMETextXMLCharsetUTF8               = MIMETextXML + "; " + CharsetUTF8
	MIMEApplicationForm                  = "application/x-www-form-urlencoded"
	MIMEApplicationProtobuf              = "application/protobuf"
	MIMEApplicationMsgpack               = "application/msgpack"
	MIMETextHTML                         = "text/html"
	MIMETextHTMLCharsetUTF8              = MIMETextHTML + "; " + CharsetUTF8
	MIMETextPlain                        = "text/plain"
	MIMETextPlainCharsetUTF8             = MIMETextPlain + "; " + CharsetUTF8
	MIMEMultipartForm                    = "multipart/form-data"
	MIMEOctetStream                      = "application/octet-stream"
	MIMEJsonAPI                          = "application/vnd.api+json"
	MIMEJsonStream                       = "application/x-json-stream"
	MIMEImagePng                         = "image/png"
	MIMEImageJpeg                        = "image/jpeg"
	MIMEImageGif                         = "image/gif"
)
View Source
const (
	MethodGet     = 0x0001 // "GET"
	MethodHead    = 0x0002 // "HEAD"
	MethodPost    = 0x0004 // "POST"
	MethodPut     = 0x0008 // "PUT"
	MethodPatch   = 0x0010 // "PATCH"
	MethodDelete  = 0x0020 // "DELETE"
	MethodConnect = 0x0040 // "CONNECT"
	MethodOptions = 0x0080 // "OPTIONS"
	MethodTrace   = 0x0100 // "TRACE"
	MethodAny     = 0xffff
	MethodGetPost = MethodGet | MethodPost
)
View Source
const (
	EchoPathStyle = PathStyleEnum(0)
	GinPathStyle  = PathStyleEnum(1)
	JavaPathStyle = PathStyleEnum(2)
)
View Source
const DefaultWildCardName = "@_@"

DefaultWildCardName 默认统配符的名称

View Source
const WebContextKey = "@WebCtx"

WebContextKey WebContext 和 NativeContext 相互转换的 Key

Variables

View Source
var RpcInvoke = defaultRpcInvoke

RpcInvoke 可自定义的 rpc 执行函数

Functions

func BodyParam

func BodyParam(name string, schema *spec.Schema) *spec.Parameter

BodyParam creates a body parameter

func GetMethod

func GetMethod(method uint32) []string

GetMethod 返回 method 对应的 HTTP 方法

func HeaderParam

func HeaderParam(name string, typ, format string) *spec.Parameter

HeaderParam creates a header parameter, this is always required by default

func InvokeHandler

func InvokeHandler(ctx WebContext, fn Handler, filters []Filter)

InvokeHandler 执行 Web 处理函数

func NewBindResponse

func NewBindResponse(i interface{}, description string) *spec.Response

NewBindResponse creates a new response instance

func NewDefaultValidator

func NewDefaultValidator() *defaultValidator

NewDefaultValidator defaultValidator 的构造函数

func NewDefaultWebMapping

func NewDefaultWebMapping() *defaultWebMapping

NewDefaultWebMapping defaultWebMapping 的构造函数

func NewResponse

func NewResponse(description string) *spec.Response

NewResponse creates a new response instance

func PathParam

func PathParam(name string, typ, format string) *spec.Parameter

PathParam creates a path parameter, this is always required

func ReDoc

func ReDoc(ctx WebContext)

ReDoc redoc 响应函数

func ToPathStyle

func ToPathStyle(path string, style PathStyleEnum) (string, string)

ToPathStyle 将 URL 转换为指定风格的表示形式

func Validate

func Validate(i interface{}) error

Validate 参数校验

Types

type BaseWebContainer

type BaseWebContainer struct {
	WebMapping
	// contains filtered or unexported fields
}

BaseWebContainer WebContainer 的通用部分

func NewBaseWebContainer

func NewBaseWebContainer(config ContainerConfig) *BaseWebContainer

NewBaseWebContainer BaseWebContainer 的构造函数

func (*BaseWebContainer) AddFilter

func (c *BaseWebContainer) AddFilter(filter ...Filter)

AddFilter 添加过滤器

func (*BaseWebContainer) AddRouter

func (c *BaseWebContainer) AddRouter(router *Router)

AddRouter 添加新的路由信息

func (*BaseWebContainer) Address

func (c *BaseWebContainer) Address() string

Address 返回监听地址

func (*BaseWebContainer) Config

func (c *BaseWebContainer) Config() ContainerConfig

Config 获取 Web 容器配置

func (*BaseWebContainer) EnableSwagger

func (c *BaseWebContainer) EnableSwagger() bool

EnableSwagger 是否启用 Swagger 功能

func (*BaseWebContainer) GetErrorCallback

func (c *BaseWebContainer) GetErrorCallback() func(error)

GetErrorCallback 返回容器自身的错误回调

func (*BaseWebContainer) GetFilters

func (c *BaseWebContainer) GetFilters() []Filter

GetFilters 返回过滤器列表

func (*BaseWebContainer) GetLoggerFilter

func (c *BaseWebContainer) GetLoggerFilter() Filter

GetLoggerFilter 获取 Logger Filter

func (*BaseWebContainer) GetRecoveryFilter

func (c *BaseWebContainer) GetRecoveryFilter() Filter

GetRecoveryFilter 获取 Recovery Filter

func (*BaseWebContainer) PreStart

func (c *BaseWebContainer) PreStart()

PreStart 执行 Start 之前的准备工作

func (*BaseWebContainer) PrintMapper

func (c *BaseWebContainer) PrintMapper(m *Mapper)

PrintMapper 打印路由注册信息

func (*BaseWebContainer) ResetFilters

func (c *BaseWebContainer) ResetFilters(filters []Filter)

ResetFilters 重新设置过滤器列表

func (*BaseWebContainer) SetEnableSwagger

func (c *BaseWebContainer) SetEnableSwagger(enable bool)

SetEnableSwagger 设置是否启用 Swagger 功能

func (*BaseWebContainer) SetErrorCallback

func (c *BaseWebContainer) SetErrorCallback(fn func(error))

SetErrorCallback 设置容器自身的错误回调

func (*BaseWebContainer) SetLoggerFilter

func (c *BaseWebContainer) SetLoggerFilter(filter Filter)

SetLoggerFilter 设置 Logger Filter

func (*BaseWebContainer) SetRecoveryFilter

func (c *BaseWebContainer) SetRecoveryFilter(filter Filter)

设置 Recovery Filter

func (*BaseWebContainer) Swagger

func (c *BaseWebContainer) Swagger() *Swagger

Swagger 返回和容器绑定的 Swagger 对象

type ContainerConfig

type ContainerConfig struct {
	IP        string // 监听 IP
	Port      int    // 监听端口
	EnableSSL bool   // 使用 SSL
	KeyFile   string // SSL 证书
	CertFile  string // SSL 秘钥

	ReadTimeout  time.Duration
	WriteTimeout time.Duration
}

ContainerConfig Web 容器配置

type DefaultFilterChain

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

DefaultFilterChain 默认的过滤器链条

func NewDefaultFilterChain

func NewDefaultFilterChain(filters []Filter) *DefaultFilterChain

NewDefaultFilterChain DefaultFilterChain 的构造函数

func (*DefaultFilterChain) Next

func (chain *DefaultFilterChain) Next(ctx WebContext)

type DefinitionField

type DefinitionField struct {
	Description string
	Example     interface{}
	Enums       []interface{}
}

type Filter

type Filter interface {
	// Invoke 通过 chain.Next() 驱动链条向后执行
	Invoke(ctx WebContext, chain FilterChain)
}

Filter 过滤器接口

func HandlerFilter

func HandlerFilter(fn Handler) Filter

HandlerFilter 把 Web 处理接口转换成过滤器

type FilterChain

type FilterChain interface {
	Next(ctx WebContext)
}

FilterChain 过滤器链条接口

type Handler

type Handler interface {
	// Invoke 响应函数
	Invoke(WebContext)

	// FileLine 获取用户函数的文件名、行号以及函数名称
	FileLine() (file string, line int, fnName string)
}

Handler Web 处理接口

func BIND

func BIND(fn interface{}) Handler

BIND 转换成 BIND 形式的 Web 处理接口

func FUNC

func FUNC(fn HandlerFunc) Handler

FUNC 标准 Web 处理函数的辅助函数

func HTTP

func HTTP(fn http.HandlerFunc) Handler

HTTP 标准 Http 处理函数的辅助函数

func WrapF

func WrapF(fn http.HandlerFunc) Handler

WrapF 标准 Http 处理函数的辅助函数,兼容 gin 写法

func WrapH

func WrapH(h http.Handler) Handler

WrapH 标准 Http 处理函数的辅助函数,兼容 gin 写法

type HandlerFunc

type HandlerFunc func(WebContext)

HandlerFunc 标准 Web 处理函数

type Mapper

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

Mapper 路由映射器

func NewMapper

func NewMapper(method uint32, path string, fn Handler, filters []Filter) *Mapper

NewMapper Mapper 的构造函数

func (*Mapper) Filters

func (m *Mapper) Filters() []Filter

Filters 返回 Mapper 的过滤器列表

func (*Mapper) GetSwagger

func (m *Mapper) GetSwagger() *Operation

GetSwagger 返回 Swagger 文档

func (*Mapper) Handler

func (m *Mapper) Handler() Handler

Handler 返回 Mapper 的处理函数

func (*Mapper) Key

func (m *Mapper) Key() string

Key 返回 Mapper 的标识符

func (*Mapper) Method

func (m *Mapper) Method() uint32

Method 返回 Mapper 的方法

func (*Mapper) Path

func (m *Mapper) Path() string

Path 返回 Mapper 的路径

func (*Mapper) Swagger

func (m *Mapper) Swagger(id string) *Operation

Swagger 生成并返回 Operation 对象

func (*Mapper) WithSwagger

func (m *Mapper) WithSwagger(swagger *Operation) *Mapper

WithSwagger 设置 Swagger 文档

type Operation

type Operation struct {
	*spec.Operation
	// contains filtered or unexported fields
}

Operation 封装 *spec.Operation 对象,提供更多功能

func NewOperation

func NewOperation(id string) *Operation

NewOperation creates a new operation instance.

func (*Operation) AddParam

func (o *Operation) AddParam(param *spec.Parameter) *Operation

AddParam adds a parameter to this operation

func (*Operation) BindParam

func (o *Operation) BindParam(i interface{}, description string) *Operation

Bind 绑定请求参数

func (*Operation) Deprecate

func (o *Operation) Deprecate() *Operation

Deprecate marks the operation as deprecated

func (*Operation) RemoveParam

func (o *Operation) RemoveParam(name, in string) *Operation

RemoveParam removes a parameter from the operation

func (*Operation) RespondsWith

func (o *Operation) RespondsWith(code int, response *spec.Response) *Operation

RespondsWith adds a status code response to the operation.

func (*Operation) SecuredWith

func (o *Operation) SecuredWith(name string, scopes ...string) *Operation

SecuredWith adds a security scope to this operation.

func (*Operation) Undeprecate

func (o *Operation) Undeprecate() *Operation

Undeprecate marks the operation as not deprecated

func (*Operation) WithConsumes

func (o *Operation) WithConsumes(mediaTypes ...string) *Operation

WithConsumes adds media types for incoming body values

func (*Operation) WithDefaultResponse

func (o *Operation) WithDefaultResponse(response *spec.Response) *Operation

WithDefaultResponse adds a default response to the operation.

func (*Operation) WithDescription

func (o *Operation) WithDescription(description string) *Operation

WithDescription sets the description on this operation, allows for chaining

func (*Operation) WithExternalDocs

func (o *Operation) WithExternalDocs(description, url string) *Operation

WithExternalDocs sets/removes the external docs for/from this operation.

func (*Operation) WithID

func (o *Operation) WithID(id string) *Operation

WithID sets the ID property on this operation, allows for chaining.

func (*Operation) WithProduces

func (o *Operation) WithProduces(mediaTypes ...string) *Operation

WithProduces adds media types for outgoing body values

func (*Operation) WithSchemes

func (o *Operation) WithSchemes(schemes ...string) *Operation

SetSchemes 设置服务协议

func (*Operation) WithSummary

func (o *Operation) WithSummary(summary string) *Operation

WithSummary sets the summary on this operation, allows for chaining

func (*Operation) WithTags

func (o *Operation) WithTags(tags ...string) *Operation

WithTags adds tags for this operation

type PathStyleEnum

type PathStyleEnum int

type ResponseWriter

type ResponseWriter interface {
	http.ResponseWriter

	// Returns the HTTP response status code of the current request.
	Status() int

	// Returns the number of bytes already written into the response http body.
	// See Written()
	Size() int
}

ResponseWriter Override http.ResponseWriter to supply more method.

type Router

type Router struct {
	UrlRegister
	// contains filtered or unexported fields
}

Router 路由分组

func NewRouter

func NewRouter(basePath string, filters ...Filter) *Router

NewRouter Router 的构造函数,不依赖具体的 WebMapping 对象

func (*Router) Route

func (r *Router) Route(basePath string, filters ...Filter) *Router

Route 返回和 Mapping 绑定的路由分组

type Swagger

type Swagger struct {
	spec.Swagger
}

Swagger 封装 spec.Swagger 对象,提供流式调用

func NewSwagger

func NewSwagger() *Swagger

NewSwagger swagger 的构造函数

func (*Swagger) AddApiKeySecurityDefinition

func (s *Swagger) AddApiKeySecurityDefinition(name string, in string) *Swagger

AddApiKeySecurityDefinition 添加 ApiKey 方式认证

func (*Swagger) AddBasicSecurityDefinition

func (s *Swagger) AddBasicSecurityDefinition() *Swagger

AddBasicSecurityDefinition 添加 Basic 方式认证

func (*Swagger) AddDefinition

func (s *Swagger) AddDefinition(name string, schema *spec.Schema) *Swagger

AddDefinition 添加一个定义

func (*Swagger) AddOauth2AccessCodeSecurityDefinition

func (s *Swagger) AddOauth2AccessCodeSecurityDefinition(name string, authorizationUrl string, tokenUrl string, scopes map[string]string) *Swagger

AddOauth2AccessCodeSecurityDefinition 添加 OAuth2 AccessCode 方式认证

func (*Swagger) AddOauth2ApplicationSecurityDefinition

func (s *Swagger) AddOauth2ApplicationSecurityDefinition(name string, tokenUrl string, scopes map[string]string) *Swagger

AddOauth2ApplicationSecurityDefinition 添加 OAuth2 Application 方式认证

func (*Swagger) AddOauth2ImplicitSecurityDefinition

func (s *Swagger) AddOauth2ImplicitSecurityDefinition(name string, authorizationUrl string, scopes map[string]string) *Swagger

AddOauth2ImplicitSecurityDefinition 添加 OAuth2 Implicit 方式认证

func (*Swagger) AddOauth2PasswordSecurityDefinition

func (s *Swagger) AddOauth2PasswordSecurityDefinition(name string, tokenUrl string, scopes map[string]string) *Swagger

AddOauth2PasswordSecurityDefinition 添加 OAuth2 Password 方式认证

func (*Swagger) AddPath

func (s *Swagger) AddPath(path string, method uint32, op *Operation,
	parameters ...spec.Parameter) *Swagger

AddPath 添加一个路由

func (*Swagger) BindDefinitionWithTags

func (s *Swagger) BindDefinitionWithTags(i interface{}, attachFields map[string]DefinitionField) *Swagger

BindDefinitionWithTags 绑定一个定义

func (*Swagger) BindDefinitions

func (s *Swagger) BindDefinitions(i ...interface{}) *Swagger

BindDefinitions 绑定一个定义

func (*Swagger) ReadDoc

func (s *Swagger) ReadDoc() string

ReadDoc 获取应用的 Swagger 描述内容

func (*Swagger) WithBasePath

func (s *Swagger) WithBasePath(basePath string) *Swagger

WithBasePath 设置 API 路径的前缀

func (*Swagger) WithConsumes

func (s *Swagger) WithConsumes(consumes ...string) *Swagger

WithConsumes 设置消费协议

func (*Swagger) WithContact

func (s *Swagger) WithContact(name string, url string, email string) *Swagger

WithContact 设置作者的名字、主页地址、邮箱

func (*Swagger) WithDescription

func (s *Swagger) WithDescription(description string) *Swagger

WithDescription 设置服务描述

func (*Swagger) WithExternalDocs

func (s *Swagger) WithExternalDocs(externalDocs *spec.ExternalDocumentation) *Swagger

WithExternalDocs

func (*Swagger) WithHost

func (s *Swagger) WithHost(host string) *Swagger

WithHost 设置可用服务器地址

func (*Swagger) WithID

func (s *Swagger) WithID(id string) *Swagger

WithID 设置应用 ID

func (*Swagger) WithLicense

func (s *Swagger) WithLicense(name string, url string) *Swagger

WithLicense 设置开源协议的名称、地址

func (*Swagger) WithProduces

func (s *Swagger) WithProduces(produces ...string) *Swagger

WithProduces 设置生产协议

func (*Swagger) WithSchemes

func (s *Swagger) WithSchemes(schemes ...string) *Swagger

WithSchemes 设置服务协议

func (*Swagger) WithTags

func (s *Swagger) WithTags(tags ...spec.Tag) *Swagger

WithTags 添加标签

func (*Swagger) WithTermsOfService

func (s *Swagger) WithTermsOfService(termsOfService string) *Swagger

WithTermsOfService 设置服务条款地址

func (*Swagger) WithTitle

func (s *Swagger) WithTitle(title string) *Swagger

WithTitle 设置服务名称

func (*Swagger) WithVersion

func (s *Swagger) WithVersion(version string) *Swagger

WithVersion 设置 API 版本号

type UrlRegister

type UrlRegister interface {

	// Route 返回和 Mapping 绑定的路由分组
	Route(basePath string, filters ...Filter) *Router

	// Request 注册任意 HTTP 方法处理函数
	Request(method uint32, path string, fn Handler, filters ...Filter) *Mapper

	// RequestMapping 注册任意 HTTP 方法处理函数
	RequestMapping(method uint32, path string, fn HandlerFunc, filters ...Filter) *Mapper

	// RequestBinding 注册任意 HTTP 方法处理函数
	RequestBinding(method uint32, path string, fn interface{}, filters ...Filter) *Mapper

	// HandleGet 注册 GET 方法处理函数
	HandleGet(path string, fn Handler, filters ...Filter) *Mapper

	// GetMapping 注册 GET 方法处理函数
	GetMapping(path string, fn HandlerFunc, filters ...Filter) *Mapper

	// GetBinding 注册 GET 方法处理函数
	GetBinding(path string, fn interface{}, filters ...Filter) *Mapper

	// HandlePost 注册 POST 方法处理函数
	HandlePost(path string, fn Handler, filters ...Filter) *Mapper

	// PostMapping 注册 POST 方法处理函数
	PostMapping(path string, fn HandlerFunc, filters ...Filter) *Mapper

	// PostBinding 注册 POST 方法处理函数
	PostBinding(path string, fn interface{}, filters ...Filter) *Mapper

	// HandlePut 注册 PUT 方法处理函数
	HandlePut(path string, fn Handler, filters ...Filter) *Mapper

	// PutMapping 注册 PUT 方法处理函数
	PutMapping(path string, fn HandlerFunc, filters ...Filter) *Mapper

	// PutBinding 注册 PUT 方法处理函数
	PutBinding(path string, fn interface{}, filters ...Filter) *Mapper

	// HandleDelete 注册 DELETE 方法处理函数
	HandleDelete(path string, fn Handler, filters ...Filter) *Mapper

	// DeleteMapping 注册 DELETE 方法处理函数
	DeleteMapping(path string, fn HandlerFunc, filters ...Filter) *Mapper

	// DeleteBinding 注册 DELETE 方法处理函数
	DeleteBinding(path string, fn interface{}, filters ...Filter) *Mapper
}

UrlRegister 路由注册接口

type WebContainer

type WebContainer interface {
	// WebMapping 路由表
	WebMapping

	// Config 获取 Web 容器配置
	Config() ContainerConfig

	// GetFilters 返回过滤器列表
	GetFilters() []Filter

	// ResetFilters 重新设置过滤器列表
	ResetFilters(filters []Filter)

	// AddFilter 添加过滤器
	AddFilter(filter ...Filter)

	// GetLoggerFilter 获取 Logger Filter
	GetLoggerFilter() Filter

	// SetLoggerFilter 设置 Logger Filter
	SetLoggerFilter(filter Filter)

	// GetRecoveryFilter 获取 Recovery Filter
	GetRecoveryFilter() Filter

	// SetRecoveryFilter 设置 Recovery Filter
	SetRecoveryFilter(filter Filter)

	// GetErrorCallback 返回容器自身的错误回调
	GetErrorCallback() func(error)

	// SetErrorCallback 设置容器自身的错误回调
	SetErrorCallback(fn func(error))

	// AddRouter 添加新的路由信息
	AddRouter(router *Router)

	// EnableSwagger 是否启用 Swagger 功能
	EnableSwagger() bool

	// SetEnableSwagger 设置是否启用 Swagger 功能
	SetEnableSwagger(enable bool)

	// Swagger 返回和容器绑定的 Swagger 对象
	Swagger() *Swagger

	// Start 启动 Web 容器,非阻塞
	Start()

	// Stop 停止 Web 容器,阻塞
	Stop(ctx context.Context)
}

WebContainer Web 容器

type WebContext

type WebContext interface {

	// LoggerContext 日志接口上下文
	SpringLogger.LoggerContext

	// NativeContext 返回封装的底层上下文对象
	NativeContext() interface{}

	// Get retrieves data from the context.
	Get(key string) interface{}

	// Set saves data in the context.
	Set(key string, val interface{})

	// Request returns `*http.Request`.
	Request() *http.Request

	// SetRequest sets `*http.Request`.
	SetRequest(r *http.Request)

	// IsTLS returns true if HTTP connection is TLS otherwise false.
	IsTLS() bool

	// IsWebSocket returns true if HTTP connection is WebSocket otherwise false.
	IsWebSocket() bool

	// Scheme returns the HTTP protocol scheme, `http` or `https`.
	Scheme() string

	// ClientIP implements a best effort algorithm to return the real client IP,
	// it parses X-Real-IP and X-Forwarded-For in order to work properly with
	// reverse-proxies such us: nginx or haproxy. Use X-Forwarded-For before
	// X-Real-Ip as nginx uses X-Real-Ip with the proxy's IP.
	ClientIP() string

	// Path returns the registered path for the handler.
	Path() string

	// Handler returns the matched handler by router.
	Handler() Handler

	// ContentType returns the Content-Type header of the request.
	ContentType() string

	// GetHeader returns value from request headers.
	GetHeader(key string) string

	// GetRawData return stream data.
	GetRawData() ([]byte, error)

	// PathParam returns path parameter by name.
	PathParam(name string) string

	// PathParamNames returns path parameter names.
	PathParamNames() []string

	// PathParamValues returns path parameter values.
	PathParamValues() []string

	// QueryParam returns the query param for the provided name.
	QueryParam(name string) string

	// QueryParams returns the query parameters as `url.Values`.
	QueryParams() url.Values

	// QueryString returns the URL query string.
	QueryString() string

	// FormValue returns the form field value for the provided name.
	FormValue(name string) string

	// FormParams returns the form parameters as `url.Values`.
	FormParams() (url.Values, error)

	// FormFile returns the multipart form file for the provided name.
	FormFile(name string) (*multipart.FileHeader, error)

	// SaveUploadedFile uploads the form file to specific dst.
	SaveUploadedFile(file *multipart.FileHeader, dst string) error

	// MultipartForm returns the multipart form.
	MultipartForm() (*multipart.Form, error)

	// Cookie returns the named cookie provided in the request.
	Cookie(name string) (*http.Cookie, error)

	// Cookies returns the HTTP cookies sent with the request.
	Cookies() []*http.Cookie

	// Bind binds the request body into provided type `i`. The default binder
	// does it based on Content-Type header.
	Bind(i interface{}) error

	// IsAborted 当前处理过程是否终止,为了适配 gin 的模型,未来底层统一了会去掉.
	IsAborted() bool

	// Abort 终止当前处理过程,为了适配 gin 的模型,未来底层统一了会去掉.
	Abort()

	// ResponseWriter returns `http.ResponseWriter`.
	ResponseWriter() ResponseWriter

	// Status sets the HTTP response code.
	Status(code int)

	// Header is a intelligent shortcut for c.Writer.Header().Set(key, value).
	// It writes a header in the response.
	// If value == "", this method removes the header `c.Writer.Header().Del(key)`
	Header(key, value string)

	// SetCookie adds a `Set-Cookie` header in HTTP response.
	SetCookie(cookie *http.Cookie)

	// NoContent sends a response with no body and a status code.
	NoContent(code int)

	// String writes the given string into the response body.
	String(code int, format string, values ...interface{}) error

	// HTML sends an HTTP response with status code.
	HTML(code int, html string) error

	// HTMLBlob sends an HTTP blob response with status code.
	HTMLBlob(code int, b []byte) error

	// JSON sends a JSON response with status code.
	JSON(code int, i interface{}) error

	// JSONPretty sends a pretty-print JSON with status code.
	JSONPretty(code int, i interface{}, indent string) error

	// JSONBlob sends a JSON blob response with status code.
	JSONBlob(code int, b []byte) error

	// JSONP sends a JSONP response with status code. It uses `callback`
	// to construct the JSONP payload.
	JSONP(code int, callback string, i interface{}) error

	// JSONPBlob sends a JSONP blob response with status code. It uses
	// `callback` to construct the JSONP payload.
	JSONPBlob(code int, callback string, b []byte) error

	// XML sends an XML response with status code.
	XML(code int, i interface{}) error

	// XMLPretty sends a pretty-print XML with status code.
	XMLPretty(code int, i interface{}, indent string) error

	// XMLBlob sends an XML blob response with status code.
	XMLBlob(code int, b []byte) error

	// Blob sends a blob response with status code and content type.
	Blob(code int, contentType string, b []byte) error

	// Stream sends a streaming response with status code and content type.
	Stream(code int, contentType string, r io.Reader) error

	// File sends a response with the content of the file.
	File(file string) error

	// Attachment sends a response as attachment, prompting client to save the file.
	Attachment(file string, name string) error

	// Inline sends a response as inline, opening the file in the browser.
	Inline(file string, name string) error

	// Redirect redirects the request to a provided URL with status code.
	Redirect(code int, url string) error

	// SSEvent writes a Server-Sent Event into the body stream.
	SSEvent(name string, message interface{}) error
}

WebContext 上下文接口,设计理念:为社区中优秀的 Web 服务器提供一个抽象层, 使得底层可以灵活切换,因此在功能上取这些 Web 服务器功能的交集,同时提供获取 底层对象的接口,以便在不能满足用户要求的时候使用底层实现的能力,当然要慎用。

type WebMapping

type WebMapping interface {
	UrlRegister

	// Mappers 返回映射器列表
	Mappers() map[string]*Mapper

	// AddMapper 添加一个 Mapper
	AddMapper(m *Mapper) *Mapper
}

WebMapping 路由表,Spring-Web 使用的路由规则和 echo 完全相同,并对 gin 做了适配。

type WebServer

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

WebServer 一个 WebServer 包含多个 WebContainer

func NewWebServer

func NewWebServer() *WebServer

NewWebServer WebServer 的构造函数

func (*WebServer) AddContainer

func (s *WebServer) AddContainer(container ...WebContainer) *WebServer

AddContainer 添加 WebContainer 实例

func (*WebServer) AddFilter

func (s *WebServer) AddFilter(filter ...Filter) *WebServer

AddFilter 添加共用的普通过滤器

func (*WebServer) Containers

func (s *WebServer) Containers() []WebContainer

Containers 返回 WebContainer 实例列表

func (*WebServer) Filters

func (s *WebServer) Filters() []Filter

Filters 获取过滤器列表

func (*WebServer) GetLoggerFilter

func (s *WebServer) GetLoggerFilter() Filter

GetLoggerFilter 获取 Logger Filter

func (*WebServer) GetRecoveryFilter

func (s *WebServer) GetRecoveryFilter() Filter

GetRecoveryFilter 获取 Recovery Filter

func (*WebServer) ResetFilters

func (s *WebServer) ResetFilters(filters []Filter)

ResetFilters 重新设置过滤器列表

func (*WebServer) SetErrorCallback

func (s *WebServer) SetErrorCallback(fn func(error)) *WebServer

SetErrorCallback 设置容器自身的错误回调

func (*WebServer) SetLoggerFilter

func (s *WebServer) SetLoggerFilter(filter Filter) *WebServer

SetLoggerFilter 设置共用的日志过滤器

func (*WebServer) SetRecoveryFilter

func (s *WebServer) SetRecoveryFilter(filter Filter) *WebServer

SetRecoveryFilter 设置共用的恢复过滤器

func (*WebServer) Start

func (s *WebServer) Start()

Start 启动 Web 容器,非阻塞调用

func (*WebServer) Stop

func (s *WebServer) Stop(ctx context.Context)

Stop 停止 Web 容器,阻塞调用

type WebValidator

type WebValidator interface {
	Engine() interface{}
	Validate(i interface{}) error
}

WebValidator 参数校验器接口

var Validator WebValidator

Validator 全局参数校验器

Jump to

Keyboard shortcuts

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