Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var UNIMPLEMENTED_METHOD = errors.New("unimplemented method")
方法未实现,如果某个方法未实现需要抛出此错误。
Functions ¶
Types ¶
type Factory ¶
type Factory func() WebContainer
定义 WebContainer 的工厂函数
var WebContainerFactory Factory
保存 WebContainer 的工厂函数
type Filter ¶
type Filter interface {
// 函数内部通过 chain.Next() 驱动链条向后执行
Invoke(ctx WebContext, chain *FilterChain)
}
定义 Web 过滤器
type FilterChain ¶
type FilterChain struct {
// contains filtered or unexported fields
}
定义 Web 过滤器链条
type WebBeanInitialization ¶
type WebBeanInitialization interface {
InitWebBean(c WebContainer, ctx SpringCore.SpringContext)
}
定义 Web Bean 初始化接口
type WebContainer ¶
type WebContainer interface {
// 停止 Web 容器
Stop()
// 启动 HTTP 容器
Start(address string) error
// 启动 HTTPS 容器
StartTLS(address string, certFile, keyFile string) error
// 注册 GET 方法处理函数
GET(path string, fn Handler, filters ...Filter)
// 注册 POST 方法处理函数
POST(path string, fn Handler, filters ...Filter)
// 注册 PATCH 方法处理函数
PATCH(path string, fn Handler, filters ...Filter)
// 注册 PUT 方法处理函数
PUT(path string, fn Handler, filters ...Filter)
// 注册 DELETE 方法处理函数
DELETE(path string, fn Handler, filters ...Filter)
// 注册 HEAD 方法处理函数
HEAD(path string, fn Handler, filters ...Filter)
// 注册 OPTIONS 方法处理函数
OPTIONS(path string, fn Handler, filters ...Filter)
GROUP(path string, fns ...Handler) WebGroup
USE(fns ...Handler)
GET_MIDDLEWARE_CORS(config Middleware.SpringWebCorsConfig) Handler
}
定义 Web 容器接口
type WebContext ¶
type WebContext interface {
SpringTrace.TraceContext
// 获取封装的底层上下文对象
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
// 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)
// Param returns path parameter by name.
PathParam(name string) string
// ParamNames returns path parameter names.
PathParamNames() []string
// ParamValues 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
// 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{})
// HTML sends an HTTP response with status code.
HTML(code int, html string)
// HTMLBlob sends an HTTP blob response with status code.
HTMLBlob(code int, b []byte)
// JSON sends a JSON response with status code.
JSON(code int, i interface{})
// JSONPretty sends a pretty-print JSON with status code.
JSONPretty(code int, i interface{}, indent string)
// JSONBlob sends a JSON blob response with status code.
JSONBlob(code int, b []byte)
// JSONP sends a JSONP response with status code. It uses `callback`
// to construct the JSONP payload.
JSONP(code int, callback string, i interface{})
// JSONPBlob sends a JSONP blob response with status code. It uses
// `callback` to construct the JSONP payload.
JSONPBlob(code int, callback string, b []byte)
// XML sends an XML response with status code.
XML(code int, i interface{})
// XMLPretty sends a pretty-print XML with status code.
XMLPretty(code int, i interface{}, indent string)
// XMLBlob sends an XML blob response with status code.
XMLBlob(code int, b []byte)
// Blob sends a blob response with status code and content type.
Blob(code int, contentType string, b []byte)
// Stream sends a streaming response with status code and content type.
Stream(code int, contentType string, r io.Reader)
// File sends a response with the content of the file.
File(file string)
// Attachment sends a response as attachment, prompting client to save the
// file.
Attachment(file string, name string)
// Inline sends a response as inline, opening the file in the browser.
Inline(file string, name string)
// Redirect redirects the request to a provided URL with status code.
Redirect(code int, url string)
// SSEvent writes a Server-Sent Event into the body stream.
SSEvent(name string, message interface{})
// Error invokes the registered HTTP error handler.
Error(err error)
}
定义 Web 上下文接口,设计理念:为社区中优秀的 Web 服务器提供一个抽象层,使得 底层可以灵活切换,因此在功能上取这些 Web 服务器功能的交集,同时提供获取底层对 象的接口,以便在不能满足用户要求的时候使用底层实现的能力,当然这种功能要慎用。
Click to show internal directories.
Click to hide internal directories.