Documentation ¶
Index ¶
- Variables
- func ContextWithPathParams(ctx context.Context, values url.Values) context.Context
- func CookieDecoder() transport.DecoderFunc
- func DefaultDecoderChain() transport.Decoder
- func DefaultStatusCheckFunc(status string, code int) (err error)
- func HeaderDecoder() transport.DecoderFunc
- func HyperMediaDecoder() transport.DecoderFunc
- func JSONEncoder() transport.EncoderFunc
- func JSONErrorEncoder() transport.ErrorEncoderFunc
- func JSONRequest[T any](ctx context.Context, params JSONRequestParams) (result T, err error)
- func NewServer(params *NewServerParams) (*http.Server, error)
- func NewTCPListener(addr ListenAddr) (net.Listener, error)
- func PathParamsDecoder() transport.DecoderFunc
- func PathParamsFromContext(ctx context.Context) url.Values
- func QueryParamsDecoder() transport.DecoderFunc
- func StartServer(ctx context.Context, listener net.Listener, server *http.Server) error
- func ValueDecoder(tag string, get func(request transport.Request) ValueSet) transport.DecoderFunc
- type CloudflareMeta
- type Codec
- type Context
- type DefaultJSONError
- type ErrorResponse
- type GinMux
- type Handler
- type HandlerFactory
- type HandlerFactoryFunc
- type JSONRequestParams
- type ListenAddr
- type NewServerParams
- type Request
- func (r *Request) Body() io.ReadCloser
- func (r *Request) BodyBuffer() *bytes.Buffer
- func (r *Request) Headers() http.Header
- func (r *Request) Method() string
- func (r *Request) ParseMediaType() (mediatype string, params map[string]string, err error)
- func (r *Request) Path() string
- func (r *Request) PathParams() url.Values
- func (r *Request) QueryParams() url.Values
- func (r *Request) URL() *url.URL
- func (r *Request) Underlying() any
- func (r *Request) Version() string
- func (r *Request) WithContext(ctx context.Context) transport.Request
- type ResponseWriter
- func (r *ResponseWriter) BodyBuffer() *bytes.Buffer
- func (r *ResponseWriter) BytesWritten() int64
- func (r *ResponseWriter) DelCookie(cookie http.Cookie) transport.Response
- func (r *ResponseWriter) DelCookieByName(name string) transport.Response
- func (r *ResponseWriter) GetStatusCode() int
- func (r *ResponseWriter) Headers() http.Header
- func (r *ResponseWriter) Redirect(req transport.Request, url string, code int)
- func (r *ResponseWriter) SetCookie(cookie http.Cookie) transport.Response
- func (r *ResponseWriter) SetStatusCode(i int)
- func (r *ResponseWriter) Underlying() any
- func (r *ResponseWriter) Write(b []byte) (int, error)
- type ServeMux
- type StatusCheckFunc
- type StdLibMux
- type ValueSet
Constants ¶
This section is empty.
Variables ¶
var ( ErrStatusCheckFailed = errors.New("unable to send http request") ErrInvalidHTTPRequest = errors.New("invalid http request") )
var DefaultCodec = &Codec{ Decoder: DefaultDecoderChain(), Encoder: JSONEncoder(), ErrorEncoder: JSONErrorEncoder(), }
var ErrServerStartTimeout = errors.New("http server start timeout")
Functions ¶
func ContextWithPathParams ¶
ContextWithPathParams
func CookieDecoder ¶
func CookieDecoder() transport.DecoderFunc
func DefaultDecoderChain ¶
func DefaultStatusCheckFunc ¶
func HeaderDecoder ¶
func HeaderDecoder() transport.DecoderFunc
func HyperMediaDecoder ¶
func HyperMediaDecoder() transport.DecoderFunc
func JSONEncoder ¶
func JSONEncoder() transport.EncoderFunc
JSONEncoder encodes any response as JSON and writes it to the ResponseWriter
func JSONErrorEncoder ¶
func JSONErrorEncoder() transport.ErrorEncoderFunc
JSONErrorEncoder encodes any response as JSON and writes it to the ResponseWriter
func JSONRequest ¶
func JSONRequest[T any](ctx context.Context, params JSONRequestParams) (result T, err error)
JSONRequest function is a generic HTTP client function that can send HTTP requests and decode responses into any Go struct or value. The function takes a context, HTTP method, URL, request body, and a map of headers as inputs. It uses the default HTTP client provided by Go to make the HTTP request, with the request body and headers added to the request
func NewTCPListener ¶
func NewTCPListener(addr ListenAddr) (net.Listener, error)
func PathParamsDecoder ¶
func PathParamsDecoder() transport.DecoderFunc
func PathParamsFromContext ¶
PathParamsFromContext
func QueryParamsDecoder ¶
func QueryParamsDecoder() transport.DecoderFunc
func StartServer ¶
StartServer starts the server in a non-blocking fashion It will return an error in the following cases 1. The server fails to start (port conflict) 2. The context is cancelled 3. The server takes longer than 5 seconds to start You must call server.Shutdown() to stop the server
func ValueDecoder ¶
Types ¶
type CloudflareMeta ¶
func CloudflareMetaFromHeaders ¶
func CloudflareMetaFromHeaders(header http.Header) (meta CloudflareMeta)
type DefaultJSONError ¶
func (DefaultJSONError) Error ¶
func (d DefaultJSONError) Error() string
func (DefaultJSONError) GetStatusCode ¶
func (d DefaultJSONError) GetStatusCode() int
func (DefaultJSONError) PrepareResponse ¶
func (d DefaultJSONError) PrepareResponse() any
type ErrorResponse ¶
type ErrorResponse struct { URL *url.URL `json:"url"` Method string `json:"method"` StatusCode int `json:"status_code"` Body *bytes.Buffer `json:"body"` Header http.Header `json:"header"` Err error `json:"-"` }
func NewErrorResponse ¶
func NewErrorResponse(res *http.Response) *ErrorResponse
NewErrorResponse attempts to read the response body after a request This is to improve visibility into HTTP request failures
func (*ErrorResponse) Error ¶
func (r *ErrorResponse) Error() string
func (*ErrorResponse) Unwrap ¶
func (r *ErrorResponse) Unwrap() error
func (*ErrorResponse) Wrap ¶
func (r *ErrorResponse) Wrap(err error) error
type GinMux ¶
type GinMux struct {
// contains filtered or unexported fields
}
func NewGinMuxWithMiddleware ¶
func NewGinMuxWithMiddleware(middleware ...func(engine *gin.Engine) gin.HandlerFunc) *GinMux
type Handler ¶
type Handler struct { Path string Methods []string Handler transport.Handler Codec transport.Codec // TODO: think about emitting errors at a higher level // Maybe we need a logger here OnError func(err error) }
Handler is an HTTP adapter for transport.Handler
func (*Handler) ServeHTTP ¶
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler
func (*Handler) WithMethods ¶
type HandlerFactory ¶
type HandlerFactory interface {
HTTPHandlerFactory(*middleware.Registry) []*Handler
}
type HandlerFactoryFunc ¶
type HandlerFactoryFunc func() []*Handler
func (HandlerFactoryFunc) HTTPHandlerFactory ¶
func (h HandlerFactoryFunc) HTTPHandlerFactory() []*Handler
type JSONRequestParams ¶
type ListenAddr ¶
type ListenAddr string
type NewServerParams ¶
type Request ¶
func NewRequest ¶
func (*Request) Body ¶
func (r *Request) Body() io.ReadCloser
func (*Request) BodyBuffer ¶
func (*Request) ParseMediaType ¶
func (*Request) PathParams ¶
func (*Request) QueryParams ¶
func (*Request) Underlying ¶
type ResponseWriter ¶
type ResponseWriter struct { http.ResponseWriter // contains filtered or unexported fields }
func NewResponse ¶
func NewResponse(w http.ResponseWriter) *ResponseWriter
func (*ResponseWriter) BodyBuffer ¶
func (r *ResponseWriter) BodyBuffer() *bytes.Buffer
func (*ResponseWriter) BytesWritten ¶
func (r *ResponseWriter) BytesWritten() int64
func (*ResponseWriter) DelCookie ¶
func (r *ResponseWriter) DelCookie(cookie http.Cookie) transport.Response
func (*ResponseWriter) DelCookieByName ¶
func (r *ResponseWriter) DelCookieByName(name string) transport.Response
func (*ResponseWriter) GetStatusCode ¶
func (r *ResponseWriter) GetStatusCode() int
func (*ResponseWriter) Headers ¶
func (r *ResponseWriter) Headers() http.Header
func (*ResponseWriter) Redirect ¶
func (r *ResponseWriter) Redirect(req transport.Request, url string, code int)
func (*ResponseWriter) SetCookie ¶
func (r *ResponseWriter) SetCookie(cookie http.Cookie) transport.Response
func (*ResponseWriter) SetStatusCode ¶
func (r *ResponseWriter) SetStatusCode(i int)
func (*ResponseWriter) Underlying ¶
func (r *ResponseWriter) Underlying() any
type StatusCheckFunc ¶
type StdLibMux ¶
type StdLibMux struct {
// contains filtered or unexported fields
}
func NewStdLibMux ¶
func NewStdLibMux() *StdLibMux