Documentation ¶
Overview ¶
Package contextx
@author: xwc1125
Package contextx ¶
@author: xwc1125
Package contextx ¶
@author: xwc1125
Package contextx ¶
@author: xwc1125
Index ¶
- Constants
- Variables
- func Data(ctx Context, code int, data []byte)
- func FilterUrlParam(params map[string]string) map[string]interface{}
- func GetRequestID(request *http.Request) string
- func HTML(ctx Context, code int, html string)
- func JSON(ctx Context, code int, obj interface{})
- func JSONP(ctx Context, code int, callback string, obj interface{})
- func PostForm(req *http.Request, key string) string
- func ReadBody(req *http.Request) *string
- func ReadHeaders(req *http.Request) map[string]string
- func ReadHeadersFromResponse(header http.Header) map[string]string
- func ReadMultiPostForm(mpForm *multipart.Form) map[string]string
- func ReadPostForm(req *http.Request) map[string]string
- func ReadQueryParams(req *http.Request) map[string]string
- func SendFile(ctx Context, filename string, destinationName string) error
- func ServeContent(ctx Context, content io.ReadSeeker, filename string, modtime time.Time, ...) error
- func ServeFile(ctx Context, filename string, gzipCompression bool) error
- func Text(ctx Context, code int, format string, values ...interface{})
- func UrlParamMap(ctx Context) map[string]string
- func UrlParamMapWithoutPage(ctx Context) map[string]interface{}
- type Context
- type ContextX
- type Handler
- type Reader
- type Render
Constants ¶
View Source
const ( BindType_Json = "Json" BindType_Xml = "Xml" BindType_Form = "Form" BindType_Query = "Query" BindType_FormPost = "FormPost" BindType_FormMultipart = "FormMultipart" BindType_ProtoBuf = "ProtoBuf" BindType_MsgPack = "MsgPack" BindType_Yaml = "Yaml" BindType_Header = "Header" BindType_Params = "Params" )
BindType
View Source
const ( ContentTypeHeaderKey = "Content-Type" ContentDispositionHeaderKey = "Content-Disposition" ContentLengthHeaderKey = "Content-Length" ContentEncodingHeaderKey = "Content-Encoding" )
Variables ¶
View Source
var ( RequestIDKey = "X-Request-Id" // MaxInMemoryMultipartSize 32 MB in memory max MaxInMemoryMultipartSize = int64(32000000) )
Functions ¶
func FilterUrlParam ¶
func GetRequestID ¶
func ReadHeadersFromResponse ¶
ReadHeadersFromResponse 从响应中读取头部
func ServeContent ¶
func UrlParamMap ¶
func UrlParamMapWithoutPage ¶
Types ¶
type Context ¶
type Context interface { context.Context Request() *http.Request ResponseWriter() http.ResponseWriter RequestId() string Next() Abort() // 终止。如果授权失败(例如:密码不匹配),请调用Abort以确保不调用此请求的其余处理程序 AbortWithStatus(code int) AbortWithStatusJSON(code int, jsonObj interface{}) IsAborted() bool // 判断当前context是否已终止 Param(key string) string Query(key string) string PostForm(key string) string FormFile(name string) (*multipart.FileHeader, error) MultipartForm() (*multipart.Form, error) SaveUploadedFile(file *multipart.FileHeader, dst string) error Bind(obj interface{}, bindType ...string) error ContentType() string Set(key string, value interface{}) Get(key string) (value interface{}, exists bool) GetString(key string) (s string) GetBool(key string) (b bool) GetInt64(key string) (i64 int64) Status(code int) GetStatus() int Header(key, value string) GetHeader(key string) string SetCookie(cookie *http.Cookie) GetCookie(name string) (string, error) Redirect(code int, location string) }
type ContextX ¶
type ContextX struct { Ctx context.Context Cancel context.CancelFunc }
func NewContextX ¶
func NewContextXWithCancel ¶
func NewContextXWithCancel(ctx context.Context, cancel context.CancelFunc) *ContextX
type Reader ¶
type Reader struct { ContentType string ContentLength int64 Reader io.Reader Headers map[string]string }
Reader contains the IO reader and its length, and custom ContentType and other headers.
func (Reader) Render ¶
func (r Reader) Render(w http.ResponseWriter) (err error)
Render (Reader) writes data with custom ContentType and headers.
func (Reader) WriteContentType ¶
func (r Reader) WriteContentType(w http.ResponseWriter)
WriteContentType (Reader) writes custom ContentType.
type Render ¶
type Render interface { // Render writes data with custom ContentType. Render(http.ResponseWriter) error // WriteContentType writes custom ContentType. WriteContentType(w http.ResponseWriter) }
Render interface is to be implemented by JSON, XML, HTML, YAML and so on.
Click to show internal directories.
Click to hide internal directories.