Documentation
¶
Index ¶
- Constants
- Variables
- func GetContentType(header http.Header) string
- func IsContext(o interface{}) bool
- func IsError(o interface{}) bool
- func IsRequestConfig(o interface{}) bool
- type BodyEncoder
- type BuildOption
- type ContentTypeAlias
- type DefaultJSONEncoder
- type DefaultTextEncoder
- type Factory
- type RequestConfig
- type RequestContext
- type RequestError
- type RequestHandler
- type RequestMethod
- type RequestMiddleware
- type RequestMiddlewareDesprate
- type TagMap
Constants ¶
View Source
const ( ContentTypeJson = "application/json" ContentTypeText = "text/plain" ContentTypeForm = "application/x-www-form-urlencoded" )
View Source
const ( // alias for ContentTypeJson ContentTypeAliasJson ContentTypeAlias = "json" // alias for ContentTypeText ContentTypeAliasText = "text" // alias for ContentTypeForm ContentTypeAliasForm = "form" )
View Source
const ( HeaderAccept = "Accept" HeaderAcceptEncoding = "Accept-Encoding" HeaderContentType = "Content-Type" HeaderContentEncoding = "Content-Encoding" HeaderContentLength = "Content-Length" HeaderUserAgent = "User-Agent" )
View Source
const ( APIFuncArgTagParam = "param" APIFuncArgTagHeader = "header" APIFuncArgTagHeaders = "headers" APIFuncArgTagBody = "body" APIFuncArgTagQuery = "query" // application/x-www-form-urlencoded APIFuncArgTagForm = "form" )
View Source
const ( TagMethod = "method" TagURL = "url" TagHeaders = "headers" )
View Source
const Version = "0.6.3"
Variables ¶
View Source
var Accept = []string{ContentTypeJson, ContentTypeText}
View Source
var AcceptEncoding = []string{"gzip", "deflate"}
View Source
var ErrInvalidBody = errors.New("cake: invalid body")
View Source
var ErrInvalidBuildTarget = errors.New("cake: invalid build target")
View Source
var ErrInvalidRequestFunction = errors.New("cake: invalid request function")
View Source
var ErrRequestFailed = errors.New("cake: request failed")
View Source
var ErrUnexpectedResponseContentType = errors.New("cake: unexpected response Content-Type")
View Source
var UserAgent = []string{"cake/" + Version}
Functions ¶
func GetContentType ¶ added in v0.4.3
GetContentType returns the content type of the request with try to get not CanonicalMIMEHeader
func IsRequestConfig ¶
func IsRequestConfig(o interface{}) bool
Types ¶
type BodyEncoder ¶
type BuildOption ¶
type BuildOption func(opt *buildOptions)
func WithBaseURL ¶
func WithBaseURL(url string) BuildOption
func WithDefaultContenType ¶ added in v0.3.0
func WithDefaultContenType(ct string) BuildOption
func WithEncoder ¶
func WithEncoder(contentType string, encoder BodyEncoder) BuildOption
func WithRequestMiddleware ¶ added in v0.2.0
func WithRequestMiddleware(mw RequestMiddleware) BuildOption
WithRequestMiddleware can be called multiple times
type ContentTypeAlias ¶ added in v0.4.0
type ContentTypeAlias string
func (ContentTypeAlias) GetContentType ¶ added in v0.4.0
func (c ContentTypeAlias) GetContentType() string
type DefaultJSONEncoder ¶
type DefaultJSONEncoder struct { }
func (*DefaultJSONEncoder) ContentType ¶
func (e *DefaultJSONEncoder) ContentType() string
func (*DefaultJSONEncoder) EncodeBody ¶
func (e *DefaultJSONEncoder) EncodeBody(body interface{}) (int, io.Reader, error)
type DefaultTextEncoder ¶
type DefaultTextEncoder struct { }
func (*DefaultTextEncoder) ContentType ¶
func (e *DefaultTextEncoder) ContentType() string
func (*DefaultTextEncoder) EncodeBody ¶
func (e *DefaultTextEncoder) EncodeBody(body interface{}) (int, io.Reader, error)
type Factory ¶
type Factory struct {
// contains filtered or unexported fields
}
func New ¶
func New(opts ...BuildOption) *Factory
func NewFactoryWithClient ¶
func NewFactoryWithClient(client *http.Client, opts ...BuildOption) *Factory
func (*Factory) Build ¶
func (f *Factory) Build(target interface{}, opts ...BuildOption) (interface{}, error)
type RequestConfig ¶
type RequestConfig struct {
// contains filtered or unexported fields
}
type RequestContext ¶ added in v0.5.0
type RequestContext struct { Request *http.Request Response *http.Response // contains filtered or unexported fields }
func (*RequestContext) Next ¶ added in v0.5.0
func (c *RequestContext) Next() error
type RequestError ¶
type RequestError interface { error Unwrap() error StatusCode() int Request() *http.Request Response() *http.Response Body() []byte }
func NewRequestError ¶
func NewRequestError(req *http.Request, res *http.Response) RequestError
type RequestHandler ¶ added in v0.5.0
type RequestHandler func(c *RequestContext) error
type RequestMethod ¶
type RequestMethod = string
const ( MethodGet RequestMethod = http.MethodGet MethodPost RequestMethod = http.MethodPost MethodPut RequestMethod = http.MethodPut MethodDelete RequestMethod = http.MethodDelete MethodHead RequestMethod = http.MethodHead MethodOptions RequestMethod = http.MethodOptions MethodPatch RequestMethod = http.MethodPatch MethodTrace RequestMethod = http.MethodTrace )
type RequestMiddleware ¶ added in v0.2.0
type RequestMiddleware = RequestHandler
type RequestMiddlewareDesprate ¶ added in v0.5.0
Source Files
¶
Click to show internal directories.
Click to hide internal directories.