Documentation ¶
Index ¶
- Variables
- type Client
- func (c *Client) Delete(uri string, in, out any, header Header) (error, int)
- func (c *Client) Get(uri string, out any, header Header) (error, int)
- func (c *Client) Patch(uri string, in, out any, header Header) (error, int)
- func (c *Client) Post(uri string, in, out any, header Header) (error, int)
- func (c *Client) PostForm(uri string, in map[string]string, out any, header Header) (error, int)
- func (c *Client) Put(uri string, in, out any, header Header) (error, int)
- type Config
- type ErrorHandler
- type Header
- type RequestEncoder
- type ResponseDecoder
Constants ¶
This section is empty.
Variables ¶
View Source
var ConfigDefault = Config{ Name: "wshops", NoDefaultUserAgentHeader: false, ReadTimeout: 6 * time.Second, WriteTimeout: 6 * time.Second, RequestEncoder: JSONEncoder, ResponseDecoder: JSONDecoder, ErrorHandler: defaultErrorHandler, }
ConfigDefault is the default config
View Source
var JSONDecoder = func(resp *fasthttp.Response, out any) error { if err := json.Unmarshal(resp.Body(), out); err != nil { return err } return nil }
View Source
var JSONEncoder = func(req *fasthttp.Request, in any) error {
req.Header.SetContentType("application/json")
return json.NewEncoder(req.BodyWriter()).Encode(in)
}
View Source
var TextDecoder = func(resp *fasthttp.Response, out any) error { s := out.(*string) *s = string(resp.Body()) return nil }
View Source
var URLEncoder = func(req *fasthttp.Request, in any) error { args := fasthttp.AcquireArgs() defer fasthttp.ReleaseArgs(args) for k, v := range in.(map[string]string) { args.Set(k, v) } if _, err := args.WriteTo(req.BodyWriter()); err != nil { return err } req.Header.SetContentType("application/x-www-form-urlencoded") return nil }
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
type Config ¶
type Config struct { // fasthttp client configurations Name string NoDefaultUserAgentHeader bool ReadTimeout time.Duration WriteTimeout time.Duration // RequestEncoder encode request before send RequestEncoder RequestEncoder // ResponseDecoder decode response after send ResponseDecoder ResponseDecoder // ErrorHandler handle the status code without 2xx ErrorHandler ErrorHandler }
type ErrorHandler ¶
Click to show internal directories.
Click to hide internal directories.