Documentation ¶
Index ¶
- Constants
- Variables
- func BasicAuth(username, password string) string
- func CopyHttpHeader(dst, src http.Header)
- func FormatRange(start, end, total int64) string
- func GetToken(r *http.Request) string
- func HandlerWrap[REQ, RES any](service Service[*REQ, *RES]) http.Handler
- func HandlerWrapCompatibleGRPC[REQ, RES any](method funcs.GrpcServiceMethod[*REQ, *RES]) http.Handler
- func NewNoCloseRequest(req *http.Request, s []byte)
- func NewNoCloseStrRequest(req *http.Request, s string)
- func ParseDisposition(disposition string) (mediatype string, params map[string]string, err error)
- func ParseRange(rangeHeader string) (start int64, end int64, total int64, err error)
- func RespErrRep(w http.ResponseWriter, rep *errcode.ErrRep)
- func RespErrcode(w http.ResponseWriter, code errcode.ErrCode)
- func RespError(w http.ResponseWriter, code errcode.ErrCode, msg string)
- func RespSuccess[T any](w http.ResponseWriter, msg string, data T)
- func RespSuccessData(w http.ResponseWriter, data any)
- func RespSuccessMsg(w http.ResponseWriter, msg string)
- func Response[T any](w http.ResponseWriter, code errcode.ErrCode, msg string, data T)
- func SetBasicAuth(header http.Header, username, password string)
- 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 MapHeader
- type NoCloseBody
- type NoCloseStrBody
- type ReceiveData
- type ReqResp
- 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)
- type Service
- type SliceHeader
Constants ¶
const ( // ContentTypeJavascript header value for JSONP & Javascript data. ContentTypeJavascript = "text/javascript" // ContentTypeHtml is the string of text/html response header's content type value. ContentTypeHtml = "text/html" ContentTypeCss = "text/css" // ContentTypeText header value for Text data. ContentTypeText = "text/plain" // ContentTypeXml header value for XML data. ContentTypeXml = "text/xml" // ContentTypeMarkdown custom key/content type, the real is the text/html. ContentTypeMarkdown = "text/markdown" // ContentTypeYamlText header value for YAML plain text. ContentTypeYamlText = "text/yaml" // ContentTypeMultipart header value for post multipart form data. ContentTypeMultipart = "multipart/form-data" // ContentTypeOctetStream header value for binary data. ContentTypeOctetStream = "application/octet-stream" // ContentTypeWebassembly header value for web assembly files. ContentTypeWebassembly = "application/wasm" // ContentTypeJson header value for JSON data. ContentTypeJson = "application/json" // ContentTypeJsonProblem header value for JSON API problem error. // Read more at: https://tools.ietf.org/html/rfc7807 ContentTypeJsonProblem = "application/problem+json" // ContentTypeXmlProblem header value for XML API problem error. // Read more at: https://tools.ietf.org/html/rfc7807 ContentTypeXmlProblem = "application/problem+xml" ContentTypeJavascriptUnreadable = "application/javascript" // ContentTypeXmlUnreadable obsolete header value for XML. ContentTypeXmlUnreadable = "application/xml" // ContentTypeYaml header value for YAML data. ContentTypeYaml = "application/x-yaml" // ContentTypeProtobuf header value for Protobuf messages data. ContentTypeProtobuf = "application/x-protobuf" // ContentTypeMsgPack header value for MsgPack data. ContentTypeMsgPack = "application/msgpack" // ContentTypeMsgPack2 alternative header value for MsgPack data. ContentTypeMsgPack2 = "application/x-msgpack" // ContentTypeForm header value for post form data. ContentTypeForm = "application/x-www-form-urlencoded" // ContentTypeGrpc Content-Type header value for gRPC. ContentTypeGrpc = "application/grpc" ContentTypeGrpcWeb = "application/grpc-web" ContentPdf = "application/pdf" ContentJsonUtf8 = "application/json;charset=utf-8" ContentFormParam = "application/x-www-form-urlencoded;param=value" ContentImagePng = "image/png" ContentImageJpeg = "image/jpeg" ContentImageGif = "image/gif" ContentImageBmp = "image/bmp" ContentImageWebp = "image/webp" ContentImageAvif = "image/avif" ContentTypeImageHeif = "image/heif" ContentTypeImageSvg = "image/svg+xml" ContentTypeImageTiff = "image/tiff" ContentTypeImageXIcon = "image/x-icon" ContentTypeImageVndMicrosoftIcon = "image/vnd.microsoft.icon" ContentTypeCharsetUtf8 = "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" HeaderTransferEncodingChunked = "chunked" 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 ( FormDataFieldTmpl = `form-data; name="%s"` FormDataFileTmpl = `form-data; name="%s"; filename="%s"` )
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}`)
var ResponseSysErr = []byte(`{"code":-1,"msg":"system error"}`)
Functions ¶
func CopyHttpHeader ¶
func FormatRange ¶ added in v0.1.11
func HandlerWrap ¶ added in v0.3.0
func HandlerWrapCompatibleGRPC ¶ added in v0.3.0
func HandlerWrapCompatibleGRPC[REQ, RES any](method funcs.GrpcServiceMethod[*REQ, *RES]) http.Handler
func NewNoCloseRequest ¶
func NewNoCloseStrRequest ¶
func ParseDisposition ¶ added in v0.1.9
func ParseRange ¶ added in v0.1.9
func RespErrRep ¶
func RespErrRep(w http.ResponseWriter, rep *errcode.ErrRep)
func RespErrcode ¶
func RespErrcode(w http.ResponseWriter, code errcode.ErrCode)
func RespError ¶ added in v0.1.9
func RespError(w http.ResponseWriter, code errcode.ErrCode, msg string)
func RespSuccess ¶ added in v0.0.28
func RespSuccess[T any](w http.ResponseWriter, msg string, data T)
func RespSuccessData ¶ added in v0.0.28
func RespSuccessData(w http.ResponseWriter, data any)
func RespSuccessMsg ¶ added in v0.0.28
func RespSuccessMsg(w http.ResponseWriter, msg string)
func SetBasicAuth ¶ added in v0.1.9
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 HttpResponse ¶
type IHttpResponse ¶
type MapHeader ¶ added in v0.1.13
func (MapHeader) IntoHttpHeader ¶ added in v0.1.13
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 ¶
type NoCloseStrBody struct {
// contains filtered or unexported fields
}
func (*NoCloseStrBody) Close ¶
func (r *NoCloseStrBody) Close() error
func (*NoCloseStrBody) Len ¶
func (r *NoCloseStrBody) Len() int
func (*NoCloseStrBody) Size ¶
func (r *NoCloseStrBody) Size() int64
type ReceiveData ¶
type ReceiveData = ResData[json.RawMessage]
func NewReceiveData ¶ added in v0.0.8
func NewReceiveData(code errcode.ErrCode, msg string, data any) *ReceiveData
type ResAnyData ¶
func NewErrorResData ¶ added in v0.1.11
func NewErrorResData(code errcode.ErrCode, msg string) *ResAnyData
func NewResAnyData ¶ added in v0.0.8
func NewResAnyData(code errcode.ErrCode, msg string, data any) *ResAnyData
func NewSuccessResData ¶ added in v0.1.11
func NewSuccessResData(data any) *ResAnyData
type ResData ¶
type ResData[T any] struct { Code errcode.ErrCode `json:"code"` Msg string `json:"msg,omitempty"` //验证码 Data T `json:"data,omitempty"` }
ResData 主要用来接收返回,发送请使用ResAnyData
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.
type SliceHeader ¶ added in v0.1.13
type SliceHeader []string
func NewHeader ¶
func NewHeader() *SliceHeader
func (*SliceHeader) Add ¶ added in v0.1.13
func (h *SliceHeader) Add(k, v string) *SliceHeader
func (SliceHeader) Clone ¶ added in v0.1.13
func (h SliceHeader) Clone() SliceHeader
func (SliceHeader) IntoHttpHeader ¶ added in v0.1.13
func (h SliceHeader) IntoHttpHeader(header http.Header)
func (*SliceHeader) Set ¶ added in v0.1.13
func (h *SliceHeader) Set(k, v string) *SliceHeader
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. |