Documentation ¶
Index ¶
- type CallOption
- type Caller
- type DoFunc
- type Factory
- type Handler
- type HandlerOption
- func WithAllowEncoding(allowEncoding bool) HandlerOption
- func WithMaxRequestBodySize(maxRequestBodySize int64) HandlerOption
- func WithMiddleware(middlewares ...MiddlewareFunc) HandlerOption
- func WithNotFoundHandler(notFoundHandler http.Handler) HandlerOption
- func WithOnError(onError func(error, *http.Request)) HandlerOption
- func WithOptionsHandler(optionsHandler http.Handler) HandlerOption
- func WithReadTimeout(readTimeout time.Duration) HandlerOption
- func WithWriteTimeout(writeTimeout time.Duration) HandlerOption
- type InvalidContentTypeError
- type MiddlewareFunc
- type PlainTextError
- type Registrar
- type Request
- type RequestError
- type Response
- type SendFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CallOption ¶ added in v0.8.0
type CallOption interface {
// contains filtered or unexported methods
}
CallOption configures how we set up the http call.
func WithAdditionalRequestHeader ¶ added in v0.2.0
func WithAdditionalRequestHeader(headers ...http.Header) CallOption
WithAdditionalRequestHeader returns a CallOption that adds the given http headers to the request headers.
func WithErrOut ¶ added in v0.3.0
func WithErrOut(errOut error) CallOption
WithErrOut returns a CallOption that defines the error output to return as Caller.Call error.
func WithForceBody ¶ added in v0.5.0
func WithForceBody(forceBody bool) CallOption
WithForceBody returns a CallOption that forces sending input in the request body for all methods including HEAD and GET.
func WithMaxResponseBodySize ¶ added in v0.2.0
func WithMaxResponseBodySize(maxResponseBodySize int64) CallOption
WithMaxResponseBodySize returns a CallOption that limits maximum response body size.
func WithRequestHeader ¶ added in v0.2.0
func WithRequestHeader(headers ...http.Header) CallOption
WithRequestHeader returns a CallOption that sets the given http headers to the request headers.
type Caller ¶
type Caller struct {
// contains filtered or unexported fields
}
Caller is the HTTP requester to do JSON requests with the given method to the given endpoint. The method and endpoint are given from Factory.
type Factory ¶ added in v0.2.0
type Factory struct {
// contains filtered or unexported fields
}
Factory is Caller factory to create new Caller's.
func NewFactory ¶ added in v0.2.0
NewFactory creates a new Factory.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler implements http.Handler to process JSON requests based on pattern and registered methods. Handler is similar to http.ServeMux in terms of operation.
func NewHandler ¶
func NewHandler(opts ...HandlerOption) (h *Handler)
NewHandler creates a new Handler by given HandlerOption's.
type HandlerOption ¶
type HandlerOption interface {
// contains filtered or unexported methods
}
HandlerOption sets options such as middleware, read timeout, etc.
func WithAllowEncoding ¶ added in v0.2.0
func WithAllowEncoding(allowEncoding bool) HandlerOption
WithAllowEncoding returns a HandlerOption that allows encoded content types such as gzip to be returned. By default, encoding is allowed.
func WithMaxRequestBodySize ¶
func WithMaxRequestBodySize(maxRequestBodySize int64) HandlerOption
WithMaxRequestBodySize returns a HandlerOption that limits maximum request body size.
func WithMiddleware ¶
func WithMiddleware(middlewares ...MiddlewareFunc) HandlerOption
WithMiddleware returns a HandlerOption that adds middlewares.
func WithNotFoundHandler ¶ added in v0.11.0
func WithNotFoundHandler(notFoundHandler http.Handler) HandlerOption
WithNotFoundHandler returns a HandlerOption that handles requests when the pattern isn't match.
func WithOnError ¶
func WithOnError(onError func(error, *http.Request)) HandlerOption
WithOnError returns a HandlerOption that sets the function to be called on error.
func WithOptionsHandler ¶ added in v0.10.0
func WithOptionsHandler(optionsHandler http.Handler) HandlerOption
WithOptionsHandler returns a HandlerOption that handles requests with method OPTIONS.
func WithReadTimeout ¶ added in v0.9.0
func WithReadTimeout(readTimeout time.Duration) HandlerOption
WithReadTimeout returns a HandlerOption that limits maximum request body read duration.
func WithWriteTimeout ¶ added in v0.9.0
func WithWriteTimeout(writeTimeout time.Duration) HandlerOption
WithWriteTimeout returns a HandlerOption that limits maximum response body write duration.
type InvalidContentTypeError ¶ added in v0.6.0
type InvalidContentTypeError struct {
// contains filtered or unexported fields
}
InvalidContentTypeError occurs when the request or response body content type is invalid.
func (*InvalidContentTypeError) ContentType ¶ added in v0.6.0
func (e *InvalidContentTypeError) ContentType() string
ContentType returns the invalid content type.
func (*InvalidContentTypeError) Error ¶ added in v0.6.0
func (e *InvalidContentTypeError) Error() string
Error is the implementation of error.
func (*InvalidContentTypeError) Unwrap ¶ added in v0.9.6
func (e *InvalidContentTypeError) Unwrap() error
Unwrap unwraps the underlying error.
type MiddlewareFunc ¶ added in v0.2.0
MiddlewareFunc is a function type to process requests as middleware from Handler.
type PlainTextError ¶ added in v0.9.6
type PlainTextError struct {
// contains filtered or unexported fields
}
PlainTextError is the plain text error returned from http server. It is returned from Caller.Call.
func (*PlainTextError) Error ¶ added in v0.9.6
func (e *PlainTextError) Error() string
Error is the implementation of error.
func (*PlainTextError) Unwrap ¶ added in v0.9.6
func (e *PlainTextError) Unwrap() error
Unwrap unwraps the underlying error.
type Registrar ¶ added in v0.8.0
type Registrar interface { // Register registers method with the given parameters to Handler. The pattern was given from Handler.Handle. Register(method string, in interface{}, do DoFunc, opts ...HandlerOption) Registrar }
Registrar is method registrar and created by Handler.Handle.
type Request ¶
Request encapsulates http.Request and gives input from request. It is used in DoFunc and MiddlewareFunc.
type RequestError ¶ added in v0.6.0
type RequestError struct {
// contains filtered or unexported fields
}
RequestError is the request error from http.Client. It is returned from Caller.Call.
func (*RequestError) Error ¶ added in v0.6.0
func (e *RequestError) Error() string
Error is the implementation of error.
func (*RequestError) Unwrap ¶ added in v0.9.6
func (e *RequestError) Unwrap() error
Unwrap unwraps the underlying error.