Documentation
¶
Overview ¶
nolint: mnd
Index ¶
- func NewBodyWrapper(body io.ReadCloser) io.ReadCloser
- func NewResponseWrapper(responseWriter http.ResponseWriter) http.ResponseWriter
- type BodyWrapper
- type Wrapper
- func (r *Wrapper) Flush()
- func (r *Wrapper) GetRequestContext() context.Context
- func (r *Wrapper) Header() http.Header
- func (r *Wrapper) NumBytes() int64
- func (r *Wrapper) SetRequestContext(ctx context.Context)
- func (r *Wrapper) SpanStatus() (codes.Code, string)
- func (r *Wrapper) StatusCode() int
- func (r *Wrapper) Write(p []byte) (int, error)
- func (r *Wrapper) WriteHeader(statusCode int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewBodyWrapper ¶
func NewBodyWrapper(body io.ReadCloser) io.ReadCloser
NewBodyWrapper creates a new BodyWrapper that wraps the provided io.ReadCloser. When the body is Read from, it counts the number of bytes read. When Close is called, it closes the underlying body.
func NewResponseWrapper ¶
func NewResponseWrapper(responseWriter http.ResponseWriter) http.ResponseWriter
NewResponseWrapper creates a new Wrapper that wraps the provided http.ResponseWriter. The Wrapper allows for tracking the number of bytes written, the status code, and provides access to the request context. It also implements the http.Flusher interface to allow for flushing the response when needed.
Types ¶
type BodyWrapper ¶
type BodyWrapper struct {
// contains filtered or unexported fields
}
func (*BodyWrapper) Close ¶
func (bw *BodyWrapper) Close() error
Close the underlying body and returns any error encountered during closing.
func (*BodyWrapper) NumBytes ¶
func (bw *BodyWrapper) NumBytes() int64
NumBytes returns the total number of bytes read from the body.
type Wrapper ¶
type Wrapper struct {
// contains filtered or unexported fields
}
func (*Wrapper) GetRequestContext ¶
GetRequestContext retrieves the request context associated with the Wrapper. If no context has been set, it returns a background context.
func (*Wrapper) Header ¶
Header returns the header map that will be sent by WriteHeader. The Header map also is the mechanism with which Handlers can set HTTP trailers. By default, the returned map is initialized to be empty, and HTTP handlers can add key-value pairs to it as needed. The Header map is not thread-safe, so it should only be modified by the handler that is processing the request.
func (*Wrapper) SetRequestContext ¶
SetRequestContext sets the request context for the Wrapper. This context can be used to store and retrieve information related to the request being processed, such as tracing information or other metadata.
func (*Wrapper) SpanStatus ¶
SpanStatus returns the OpenTelemetry span status code and description based on the HTTP status code of the response. If WriteHeader has not been called, it returns codes.Error with a description indicating that no status code is available. If the HTTP status code is 400 or higher, it returns codes.Error with the corresponding HTTP status text as the description. For status codes below 400, it returns codes.Ok with the corresponding HTTP status text as the description.
func (*Wrapper) StatusCode ¶
StatusCode returns the HTTP status code that was sent in the response. If WriteHeader has not been called, it returns 0.
func (*Wrapper) Write ¶
Write writes the data to the connection as part of an HTTP reply. It counts the number of bytes written and returns the count along with any error encountered during writing. If WriteHeader has not yet been called, Write calls WriteHeader(http.StatusOK) before writing the data.
func (*Wrapper) WriteHeader ¶
WriteHeader sends an HTTP response header with the provided status code. If WriteHeader is called multiple times, only the first call will have an effect, and subsequent calls will be ignored. The status code is stored in the Wrapper for later retrieval, and the header is sent to the client using the underlying http.ResponseWriter.