http_client.go 573 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package http_client
  2. import (
  3. "das/application/ports"
  4. "github.com/go-resty/resty/v2"
  5. "time"
  6. )
  7. type Client struct {
  8. client *resty.Client
  9. }
  10. func New() *Client {
  11. return &Client{
  12. client: resty.New(),
  13. }
  14. }
  15. func Destroy(client *Client) {
  16. if client == nil {
  17. return
  18. }
  19. client.client = nil
  20. }
  21. func (client *Client) NewRequest(opts ...ports.NewRequestOption) ports.HttpRequest {
  22. for _, opt := range opts {
  23. opt(client)
  24. }
  25. return &Request{request: client.client.R()}
  26. }
  27. func (client *Client) SetTimeout(timeout time.Duration) {
  28. client.client.SetTimeout(timeout)
  29. }