Documentation ¶
Index ¶
- Constants
- Variables
- func CopyHttpHeader(src, dst http.Header)
- func GetToken(r *http.Request) string
- func NewNoCloseRequest(req *http.Request, s []byte)
- func NewNoCloseStrRequest(req *http.Request, s string)
- func RespErr(w http.ResponseWriter, err error)
- func RespErrMsg(w http.ResponseWriter, msg string)
- func RespErrRep(w http.ResponseWriter, rep *errcode.ErrRep)
- func RespErrcode(w http.ResponseWriter, code errcode.ErrCode)
- func Response[T any](w http.ResponseWriter, code errcode.ErrCode, msg string, data T)
- func Stream(w http.ResponseWriter)
- func StreamWriter(w http.ResponseWriter, writer func(w io.Writer) bool)
- type Body
- type HandlerFuncs
- type Handlers
- type Header
- type HttpResponse
- type IHttpResponse
- type NoCloseBody
- type NoCloseStrBody
- type ReceiveData
- type RequestAt
- type ResAnyData
- type ResData
- type ResponseRecorder
- func (rw *ResponseRecorder) Flush()
- func (rw *ResponseRecorder) Header() http.Header
- func (rw *ResponseRecorder) Reset()
- func (rw *ResponseRecorder) Result() *http.Response
- func (rw *ResponseRecorder) Write(buf []byte) (int, error)
- func (rw *ResponseRecorder) WriteHeader(code int)
- func (rw *ResponseRecorder) WriteString(str string) (int, error)
Constants ¶
const ( // ContentJavascriptHeaderValue header value for JSONP & Javascript data. ContentJavascriptHeaderValue = "text/javascript" // ContentHtmlHeaderValue is the string of text/html response header's content type value. ContentHtmlHeaderValue = "text/html" ContentCssHeaderValue = "text/css" // ContentTextHeaderValue header value for Text data. ContentTextHeaderValue = "text/plain" // ContentXmlHeaderValue header value for XML data. ContentXmlHeaderValue = "text/xml" // ContentMarkdownHeaderValue custom key/content type, the real is the text/html. ContentMarkdownHeaderValue = "text/markdown" // ContentYamlTextHeaderValue header value for YAML plain text. ContentYamlTextHeaderValue = "text/yaml" // ContentFormMultipartHeaderValue header value for post multipart form data. ContentFormMultipartHeaderValue = "multipart/form-data" // ContentBinaryHeaderValue header value for binary data. ContentBinaryHeaderValue = "application/octet-stream" // ContentWebassemblyHeaderValue header value for web assembly files. ContentWebassemblyHeaderValue = "application/wasm" // ContentJsonHeaderValue header value for JSON data. ContentJsonHeaderValue = "application/json" // ContentJsonProblemHeaderValue header value for JSON API problem error. // Read more at: https://tools.ietf.org/html/rfc7807 ContentJsonProblemHeaderValue = "application/problem+json" // ContentXmlProblemHeaderValue header value for XML API problem error. // Read more at: https://tools.ietf.org/html/rfc7807 ContentXmlProblemHeaderValue = "application/problem+xml" ContentJavascriptUnreadableHeaderValue = "application/javascript" // ContentXmlUnreadableHeaderValue obsolete header value for XML. ContentXmlUnreadableHeaderValue = "application/xml" // ContentYamlHeaderValue header value for YAML data. ContentYamlHeaderValue = "application/x-yaml" // ContentProtobufHeaderValue header value for Protobuf messages data. ContentProtobufHeaderValue = "application/x-protobuf" // ContentMsgPackHeaderValue header value for MsgPack data. ContentMsgPackHeaderValue = "application/msgpack" // ContentMsgPack2HeaderValue alternative header value for MsgPack data. ContentMsgPack2HeaderValue = "application/x-msgpack" // ContentFormHeaderValue header value for post form data. ContentFormHeaderValue = "application/x-www-form-urlencoded" // ContentGrpcHeaderValue Content-Type header value for gRPC. ContentGrpcHeaderValue = "application/grpc" ContentGrpcWebHeaderValue = "application/grpc-web" ContentPdfHeaderValue = "application/pdf" ContentJsonUtf8HeaderValue = "application/json;charset=utf-8" ContentFormParamHeaderValue = "application/x-www-form-urlencoded;param=value" ContentImagePngHeaderValue = "image/png" ContentImageJpegHeaderValue = "image/jpeg" ContentImageGifHeaderValue = "image/gif" ContentImageBmpHeaderValue = "image/bmp" ContentImageWebpHeaderValue = "image/webp" ContentImageAvifHeaderValue = "image/avif" //ContentImageHeifHeaderValue = "image/heif" ContentImageSvgHeaderValue = "image/svg+xml" ContentImageTiffHeaderValue = "image/tiff" ContentImageXIconHeaderValue = "image/x-icon" ContentImageVndMicrosoftIconHeaderValue = "image/vnd.microsoft.icon" ContentCharsetUtf8HeaderValue = "charset=UTF-8" )
const ( HeaderDeviceInfo = "Device-AuthInfo" HeaderLocation = "Location" HeaderArea = "Area" )
const ( HeaderUserAgent = "User-Agent" HeaderXForwardedFor = "X-Forwarded-For" HeaderXAccelBuffering = "X-Accel-Buffering" HeaderAuth = "HeaderAuth" HeaderContentType = "Content-Type" HeaderTrace = "Tracing" HeaderTraceID = "Tracing-ID" HeaderTraceBin = "Tracing-Bin" HeaderAuthorization = "Authorization" HeaderCookie = "Cookie" HeaderCookieValueToken = "token" HeaderCookieValueDel = "del" HeaderContentDisposition = "Content-Disposition" HeaderContentEncoding = "Content-Encoding" HeaderReferer = "Referer" HeaderAccept = "Accept" HeaderAcceptLanguage = "Accept-Language" HeaderAcceptEncoding = "Accept-Encoding" HeaderCacheControl = "Cache-Control" HeaderSetCookie = "Set-Cookie" HeaderTrailer = "Trailer" HeaderTransferEncoding = "Transfer-Encoding" HeaderInternal = "Internal" HeaderTE = "TE" HeaderLastModified = "Last-Modified" HeaderContentLength = "Content-Length" HeaderAccessControlRequestMethod = "Access-Control-Request-Method" HeaderAccessControlRequestHeaders = "Access-Control-Request-Headers" HeaderOrigin = "Origin" HeaderConnection = "Connection" HeaderRange = "Range" HeaderContentRange = "Content-Range" HeaderAcceptRanges = "Accept-Ranges" )
const ( HeaderGrpcTraceBin = "grpc-trace-bin" HeaderGrpcInternal = "grpc-internal" )
const DefaultRemoteAddr = "1.2.3.4"
DefaultRemoteAddr is the default remote address to return in RemoteAddr if an explicit DefaultRemoteAddr isn't set on ResponseRecorder.
Variables ¶
var ResponseOk = []byte(`{"code":0,"message":"OK"}`)
var ResponseSysErr = []byte(`{"code":10000,"message":"系统错误"}`)
Functions ¶
func CopyHttpHeader ¶ added in v1.5.11
func NewNoCloseRequest ¶
func NewNoCloseStrRequest ¶ added in v1.5.11
func RespErr ¶
func RespErr(w http.ResponseWriter, err error)
func RespErrMsg ¶
func RespErrMsg(w http.ResponseWriter, msg string)
func RespErrRep ¶
func RespErrRep(w http.ResponseWriter, rep *errcode.ErrRep)
func RespErrcode ¶
func RespErrcode(w http.ResponseWriter, code errcode.ErrCode)
func Stream ¶
func Stream(w http.ResponseWriter)
func StreamWriter ¶
func StreamWriter(w http.ResponseWriter, writer func(w io.Writer) bool)
Types ¶
type HandlerFuncs ¶
type HandlerFuncs []http.HandlerFunc
func (*HandlerFuncs) Add ¶
func (hs *HandlerFuncs) Add(handler http.HandlerFunc)
func (HandlerFuncs) HandlerFunc ¶
func (hs HandlerFuncs) HandlerFunc() http.HandlerFunc
func (HandlerFuncs) ServeHTTP ¶
func (hs HandlerFuncs) ServeHTTP(w http.ResponseWriter, r *http.Request)
type Header ¶ added in v1.5.11
type Header []string
func (*Header) IntoHttpHeader ¶ added in v1.5.11
type HttpResponse ¶ added in v1.5.11
type IHttpResponse ¶ added in v1.5.11
type NoCloseBody ¶
type NoCloseBody struct {
// contains filtered or unexported fields
}
func (*NoCloseBody) Close ¶
func (r *NoCloseBody) Close() error
func (*NoCloseBody) Len ¶
func (r *NoCloseBody) Len() int
func (*NoCloseBody) Size ¶
func (r *NoCloseBody) Size() int64
type NoCloseStrBody ¶ added in v1.5.11
type NoCloseStrBody struct {
// contains filtered or unexported fields
}
func (*NoCloseStrBody) Close ¶ added in v1.5.11
func (r *NoCloseStrBody) Close() error
func (*NoCloseStrBody) Len ¶ added in v1.5.11
func (r *NoCloseStrBody) Len() int
func (*NoCloseStrBody) Read ¶ added in v1.5.11
func (r *NoCloseStrBody) Read(b []byte) (n int, err error)
func (*NoCloseStrBody) Size ¶ added in v1.5.11
func (r *NoCloseStrBody) Size() int64
type ReceiveData ¶ added in v1.5.11
type ReceiveData struct { Code errcode.ErrCode `json:"code"` Message string `json:"message,omitempty"` //验证码 Details json.RawMessage `json:"details,omitempty"` }
func NewReceivesData ¶ added in v1.5.11
func NewReceivesData(code errcode.ErrCode, msg string, data any) *ReceiveData
func (*ReceiveData) Response ¶ added in v1.5.11
func (r *ReceiveData) Response(w http.ResponseWriter, httpcode int)
func (*ReceiveData) UnmarshalData ¶ added in v1.5.11
func (r *ReceiveData) UnmarshalData(v any) error
type RequestAt ¶ added in v1.3.0
func NewRequestAt ¶ added in v1.3.0
func NewRequestAt() *RequestAt
func NewRequestAtByTime ¶ added in v1.3.0
type ResAnyData ¶
type ResData ¶
type ResponseRecorder ¶
type ResponseRecorder struct { // Code is the HTTP response code set by WriteHeader. // // Note that if a Handler never calls WriteHeader or Write, // this might end up being 0, rather than the implicit // http.StatusOK. To get the implicit value, use the Result // method. Code int HeaderMap http.Header // Body is the buffer to which the Handler's Write calls are sent. // If nil, the Writes are silently discarded. Body *bytes.Buffer // Flushed is whether the Handler called Flush. Flushed bool // contains filtered or unexported fields }
ResponseRecorder is an implementation of http.ResponseWriter that records its mutations for later inspection in tests.
func NewRecorder ¶
func NewRecorder(header http.Header) *ResponseRecorder
NewRecorder returns an initialized ResponseRecorder.
func (*ResponseRecorder) Flush ¶
func (rw *ResponseRecorder) Flush()
Flush implements http.Flusher. To test whether Flush was called, see rw.Flushed.
func (*ResponseRecorder) Header ¶
func (rw *ResponseRecorder) Header() http.Header
Header implements http.ResponseWriter. It returns the response headers to mutate within a handler. To test the headers that were written after a handler completes, use the Result method and see the returned Response value's Header.
func (*ResponseRecorder) Reset ¶
func (rw *ResponseRecorder) Reset()
func (*ResponseRecorder) Result ¶
func (rw *ResponseRecorder) Result() *http.Response
Result returns the response generated by the handler.
The returned Response will have at least its StatusCode, Header, Body, and optionally Trailer populated. More fields may be populated in the future, so callers should not DeepEqual the result in tests.
The Response.Header is a snapshot of the headers at the time of the first write call, or at the time of this call, if the handler never did a write.
The Response.Body is guaranteed to be non-nil and Body.Read call is guaranteed to not return any error other than io.EOF.
Result must only be called after the handler has finished running.
func (*ResponseRecorder) Write ¶
func (rw *ResponseRecorder) Write(buf []byte) (int, error)
Write implements http.ResponseWriter. The data in buf is written to rw.Body, if not nil.
func (*ResponseRecorder) WriteHeader ¶
func (rw *ResponseRecorder) WriteHeader(code int)
WriteHeader implements http.ResponseWriter.
func (*ResponseRecorder) WriteString ¶
func (rw *ResponseRecorder) WriteString(str string) (int, error)
WriteString implements io.StringWriter. The data in str is written to rw.Body, if not nil.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
web
`grpcweb` implements the gRPC-Web spec as a wrapper around a gRPC-Go Server.
|
`grpcweb` implements the gRPC-Web spec as a wrapper around a gRPC-Go Server. |
Package httprouter is a trie based high performance HTTP request router.
|
Package httprouter is a trie based high performance HTTP request router. |