1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- package http_client
- import (
- "github.com/go-resty/resty/v2"
- "time"
- )
- type NewRequestOption func(client *Client)
- func WithNewRequestTimeout(timeout time.Duration) NewRequestOption {
- return func(client *Client) {
- client.setTimeout(timeout)
- }
- }
- type Client struct {
- client *resty.Client
- }
- func New() *Client {
- return &Client{
- client: resty.New(),
- }
- }
- func Destroy(client *Client) {
- if client == nil {
- return
- }
- client.client = nil
- }
- func (client *Client) NewRequest(opts ...NewRequestOption) *Request {
- for _, opt := range opts {
- opt(client)
- }
- return &Request{request: client.client.R()}
- }
- func (client *Client) setTimeout(timeout time.Duration) {
- client.client.SetTimeout(timeout)
- }
|