Documentation
¶
Index ¶
- Constants
- Variables
- func BasicAuth(username, password string) string
- func CommonResponseWrite(w ICommonResponseWriter, httpres IHttpResponse) (int, error)
- func CopyHttpHeader(dst, src http.Header)
- func FormatContentDisposition(filename string) string
- func FormatContentRange(start, end, total int64) string
- func FormatRange(start, end int64) string
- func GetContentLength(header http.Header) int64
- func GetToken(r *http.Request) string
- func HandlerWrap[REQ, RES any](service Service[*REQ, *RES]) http.Handler
- func HandlerWrapCompatibleGRPC[REQ, RES any](method types.GrpcServiceMethod[*REQ, *RES]) http.Handler
- func HeaderIntoHttpHeader(header Header, httpHeader http.Header)
- func NewNoCloseRequest(req *http.Request, s []byte)
- func NewNoCloseStrRequest(req *http.Request, s string)
- func ParseContentDisposition(header string) (string, error)
- func ParseContentRange(rangeHeader string) (start int64, end int64, total int64, err error)
- func ParseDisposition(disposition string) (mediatype string, params map[string]string, err error)
- func ParseRange(header string) (int64, int64, error)
- func RespErrCodeMsg(w http.ResponseWriter, code errcode.ErrCode, msg string)
- func RespErrRep(w http.ResponseWriter, rep *errcode.ErrRep) (int, error)
- func RespErrRepStatus(w http.ResponseWriter, rep *errcode.ErrRep, statusCode int) (int, error)
- func RespError(w http.ResponseWriter, err error) (int, error)
- func RespStreamWrite(w http.ResponseWriter, dataSource iter.Seq[[]byte])
- func RespSuccess[T any](w http.ResponseWriter, msg string, data T) (int, error)
- func RespSuccessData(w http.ResponseWriter, data any) (int, error)
- func RespSuccessMsg(w http.ResponseWriter, msg string) (int, error)
- func RespWrite(w http.ResponseWriter, httpres IHttpResponse) (int, error)
- func Response[T any](w http.ResponseWriter, code errcode.ErrCode, msg string, data T) (int, error)
- func ResponseStatus[T any](w http.ResponseWriter, code errcode.ErrCode, msg string, data T, ...) (int, error)
- func SetBasicAuth(header http.Header, username, password string)
- func UnWarpContext(ctx context.Context) any
- func WarpContext(v any) context.Context
- type Body
- type CommonHttpResponseTo
- type CommonResponseWriter
- type ErrRep
- type HandlerFuncs
- type Handlers
- type Header
- type HttpHeader
- type HttpResponse
- type HttpResponseRawBody
- type HttpResponseStream
- type ICommonHttpResponseTo
- type ICommonResponseTo
- type ICommonResponseWriter
- type IHttpResponse
- type IHttpResponseTo
- type IntoHttpHeader
- type MapHeader
- type NoCloseBody
- type NoCloseStrBody
- type RawBody
- type ReceiveData
- type ReqResp
- type RespAnyData
- type RespData
- 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
- func (h *SliceHeader) Add(k, v string)
- func (h SliceHeader) Clone() SliceHeader
- func (h *SliceHeader) Get(k string) string
- func (h SliceHeader) IntoHttpHeader(header http.Header)
- func (h *SliceHeader) Range(f func(key, value string))
- func (h *SliceHeader) Set(k, v string)
- func (h *SliceHeader) Values(k string) []string
- type WriterToCloser
Constants ¶
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 = json.RawMessage(`{"code":0}`)
var ResponseSysErr = json.RawMessage(`{"code":-1,"msg":"system error"}`)
Functions ¶
func CommonResponseWrite ¶ added in v0.5.0
func CommonResponseWrite(w ICommonResponseWriter, httpres IHttpResponse) (int, error)
func CopyHttpHeader ¶
func FormatContentDisposition ¶ added in v0.8.9
func FormatContentRange ¶ added in v0.8.9
func FormatRange ¶ added in v0.1.11
func GetContentLength ¶ added in v0.9.0
func HandlerWrap ¶ added in v0.3.0
func HandlerWrapCompatibleGRPC ¶ added in v0.3.0
func HandlerWrapCompatibleGRPC[REQ, RES any](method types.GrpcServiceMethod[*REQ, *RES]) http.Handler
func HeaderIntoHttpHeader ¶ added in v0.11.0
func NewNoCloseRequest ¶
func NewNoCloseStrRequest ¶
func ParseContentDisposition ¶ added in v0.8.9
func ParseContentRange ¶ added in v0.8.9
func ParseDisposition ¶ added in v0.1.9
func RespErrCodeMsg ¶ added in v0.10.0
func RespErrCodeMsg(w http.ResponseWriter, code errcode.ErrCode, msg string)
func RespErrRep ¶
func RespErrRepStatus ¶ added in v0.15.0
func RespStreamWrite ¶ added in v0.15.0
func RespStreamWrite(w http.ResponseWriter, dataSource iter.Seq[[]byte])
func RespSuccess ¶ added in v0.0.28
func RespSuccessData ¶ added in v0.0.28
func RespSuccessData(w http.ResponseWriter, data any) (int, error)
func RespSuccessMsg ¶ added in v0.0.28
func RespSuccessMsg(w http.ResponseWriter, msg string) (int, error)
func RespWrite ¶ added in v0.15.0
func RespWrite(w http.ResponseWriter, httpres IHttpResponse) (int, error)
func ResponseStatus ¶ added in v0.15.0
func SetBasicAuth ¶ added in v0.1.9
func UnWarpContext ¶ added in v0.3.7
func WarpContext ¶ added in v0.3.7
Types ¶
type CommonHttpResponseTo ¶ added in v0.5.0
type CommonHttpResponseTo struct {
IHttpResponseTo
}
type CommonResponseWriter ¶ added in v0.5.0
type CommonResponseWriter struct {
http.ResponseWriter
}
func (*CommonResponseWriter) SetHeader ¶ added in v0.10.0
func (w *CommonResponseWriter) SetHeader(k, v string)
func (*CommonResponseWriter) Status ¶ added in v0.5.0
func (w *CommonResponseWriter) Status(code int)
type ErrRep ¶ added in v0.10.0
func ErrRepFrom ¶ added in v0.10.0
func NewErrorRespData ¶ added in v0.15.0
func (*ErrRep) Response ¶ added in v0.10.0
func (res *ErrRep) Response(w http.ResponseWriter) (int, error)
func (*ErrRep) ResponseStatus ¶ added in v0.15.0
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 HttpHeader ¶ added in v0.10.0
func (HttpHeader) Add ¶ added in v0.10.0
func (h HttpHeader) Add(k, v string)
func (HttpHeader) Get ¶ added in v0.10.0
func (h HttpHeader) Get(k string) string
func (HttpHeader) IntoHttpHeader ¶ added in v0.10.0
func (h HttpHeader) IntoHttpHeader(header http.Header)
func (HttpHeader) Range ¶ added in v0.10.0
func (h HttpHeader) Range(f func(key, value string))
func (HttpHeader) Set ¶ added in v0.10.0
func (h HttpHeader) Set(k, v string)
func (HttpHeader) Values ¶ added in v0.10.0
func (h HttpHeader) Values(k string) []string
type HttpResponse ¶
type HttpResponse struct { Status int `json:"status,omitempty"` Headers MapHeader `json:"header,omitempty"` Body WriterToCloser `json:"body,omitempty"` }
func (*HttpResponse) Close ¶ added in v0.3.7
func (res *HttpResponse) Close() error
func (*HttpResponse) Header ¶
func (res *HttpResponse) Header() Header
func (*HttpResponse) Response ¶ added in v0.3.7
func (res *HttpResponse) Response(w http.ResponseWriter) (int, error)
func (*HttpResponse) StatusCode ¶
func (res *HttpResponse) StatusCode() int
type HttpResponseRawBody ¶ added in v0.3.7
type HttpResponseRawBody struct { Status int `json:"status,omitempty"` Headers MapHeader `json:"header,omitempty"` Body []byte `json:"body,omitempty"` }
func (*HttpResponseRawBody) Close ¶ added in v0.3.7
func (res *HttpResponseRawBody) Close() error
func (*HttpResponseRawBody) Header ¶ added in v0.3.7
func (res *HttpResponseRawBody) Header() Header
func (*HttpResponseRawBody) Response ¶ added in v0.3.7
func (res *HttpResponseRawBody) Response(w http.ResponseWriter) (int, error)
func (*HttpResponseRawBody) StatusCode ¶ added in v0.3.7
func (res *HttpResponseRawBody) StatusCode() int
type HttpResponseStream ¶ added in v0.5.0
type HttpResponseStream struct { Status int `json:"status,omitempty"` Headers MapHeader `json:"header,omitempty"` Body iter.Seq[[]byte] `json:"body,omitempty"` }
func (*HttpResponseStream) Close ¶ added in v0.5.0
func (res *HttpResponseStream) Close() error
func (*HttpResponseStream) Header ¶ added in v0.5.0
func (res *HttpResponseStream) Header() Header
func (*HttpResponseStream) StatusCode ¶ added in v0.5.0
func (res *HttpResponseStream) StatusCode() int
type ICommonHttpResponseTo ¶ added in v0.5.0
type ICommonHttpResponseTo interface {
Response(w CommonResponseWriter) (int, error)
}
type ICommonResponseTo ¶ added in v0.10.0
type ICommonResponseTo interface {
Response(w ICommonResponseWriter) (int, error)
}
type ICommonResponseWriter ¶ added in v0.5.0
type IHttpResponse ¶
type IHttpResponseTo ¶ added in v0.5.0
type IHttpResponseTo interface {
Response(w http.ResponseWriter) (int, error)
}
type IntoHttpHeader ¶ added in v0.10.0
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 = RespData[json.RawMessage]
func NewReceiveData ¶ added in v0.0.8
func NewReceiveData(code errcode.ErrCode, msg string, data any) *ReceiveData
type RespAnyData ¶ added in v0.15.0
func NewRespAnyData ¶ added in v0.15.0
func NewRespAnyData(code errcode.ErrCode, msg string, data any) *RespAnyData
func NewSuccessRespData ¶ added in v0.15.0
func NewSuccessRespData(data any) *RespAnyData
type RespData ¶ added in v0.15.0
type RespData[T any] struct { Code errcode.ErrCode `json:"code"` Msg string `json:"msg,omitempty"` //验证码 Data T `json:"data,omitempty"` }
RespData 主要用来接收返回,发送请使用ResAnyData
func NewRespData ¶ added in v0.15.0
func (*RespData[T]) Response ¶ added in v0.15.0
func (res *RespData[T]) Response(w http.ResponseWriter) (int, error)
func (*RespData[T]) ResponseStatus ¶ added in v0.15.0
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 Headers 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)
func (SliceHeader) Clone ¶ added in v0.1.13
func (h SliceHeader) Clone() SliceHeader
func (*SliceHeader) Get ¶ added in v0.10.0
func (h *SliceHeader) Get(k string) string
func (SliceHeader) IntoHttpHeader ¶ added in v0.1.13
func (h SliceHeader) IntoHttpHeader(header http.Header)
func (*SliceHeader) Range ¶ added in v0.10.0
func (h *SliceHeader) Range(f func(key, value string))
func (*SliceHeader) Set ¶ added in v0.1.13
func (h *SliceHeader) Set(k, v string)
func (*SliceHeader) Values ¶ added in v0.10.0
func (h *SliceHeader) Values(k string) []string
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. |