wrapper

package
v1.16.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2023 License: Apache-2.0 Imports: 18 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HTTPHandlerDefaultRoot added in v1.14.3

func HTTPHandlerDefaultRoot(w http.ResponseWriter, r *http.Request)

HTTPHandlerDefaultRoot default root http handler

func HTTPHandlerMemstats added in v1.14.3

func HTTPHandlerMemstats(w http.ResponseWriter, r *http.Request)

HTTPHandlerMemstats calculate runtime statistic

func HTTPMiddlewareCORS added in v1.14.0

func HTTPMiddlewareCORS(
	allowMethods, allowHeaders, allowOrigins []string,
	exposeHeaders []string,
	allowCredential bool,
) func(http.Handler) http.Handler

HTTPMiddlewareCORS middleware wrapper for cors

func HTTPMiddlewareLog added in v1.15.0

func HTTPMiddlewareLog(cfg HTTPMiddlewareConfig) func(http.Handler) http.Handler

HTTPMiddlewareLog middleware

func HTTPMiddlewareTracer added in v1.14.0

func HTTPMiddlewareTracer(cfg HTTPMiddlewareConfig) func(http.Handler) http.Handler

HTTPMiddlewareTracer middleware wrapper for tracer

Types

type HTTPMiddlewareConfig added in v1.15.4

type HTTPMiddlewareConfig struct {
	MaxLogSize  int
	DisableFunc func(r *http.Request) bool
	Writer      io.Writer
	OnPanic     func(panicMessage interface{}) (respCode int, respMessage string)
}

type HTTPResponse

type HTTPResponse struct {
	Success bool        `json:"success"`
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Meta    interface{} `json:"meta,omitempty"`
	Data    interface{} `json:"data,omitempty"`
	Errors  interface{} `json:"errors,omitempty"`
}

HTTPResponse default candi http response format

func NewHTTPResponse

func NewHTTPResponse(code int, message string, params ...interface{}) *HTTPResponse

NewHTTPResponse for create common response

func (*HTTPResponse) JSON

func (resp *HTTPResponse) JSON(w http.ResponseWriter) error

JSON for set http JSON response (Content-Type: application/json) with parameter is http response writer

func (*HTTPResponse) XML

func (resp *HTTPResponse) XML(w http.ResponseWriter) error

XML for set http XML response (Content-Type: application/xml)

type WrapHTTPResponseWriter

type WrapHTTPResponseWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

WrapHTTPResponseWriter wrapper

func NewWrapHTTPResponseWriter

func NewWrapHTTPResponseWriter(responseBuff *bytes.Buffer, httpResponseWriter http.ResponseWriter) *WrapHTTPResponseWriter

NewWrapHTTPResponseWriter init new wrapper for http response writter

func (*WrapHTTPResponseWriter) GetContent added in v1.14.11

func (w *WrapHTTPResponseWriter) GetContent() []byte

GetContent get response content

func (*WrapHTTPResponseWriter) GetContentLength added in v1.14.11

func (w *WrapHTTPResponseWriter) GetContentLength() int

GetContentLength get response content length

func (*WrapHTTPResponseWriter) Header

func (w *WrapHTTPResponseWriter) Header() http.Header

Header Satisfy the http.ResponseWriter interface

func (*WrapHTTPResponseWriter) SetMaxWriteSize added in v1.14.11

func (w *WrapHTTPResponseWriter) SetMaxWriteSize(max int)

SetMaxWriteSize set max write size to buffer

func (*WrapHTTPResponseWriter) StatusCode

func (w *WrapHTTPResponseWriter) StatusCode() int

StatusCode give a way to get the Code

func (*WrapHTTPResponseWriter) Write

func (w *WrapHTTPResponseWriter) Write(data []byte) (int, error)

func (*WrapHTTPResponseWriter) WriteHeader

func (w *WrapHTTPResponseWriter) WriteHeader(statusCode int)

WriteHeader method

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL