client.go 629 B

123456789101112131415161718192021222324252627282930313233343536
  1. package client
  2. import (
  3. "crypto/tls"
  4. "github.com/go-resty/resty/v2"
  5. "time"
  6. )
  7. type Client struct {
  8. restyClient *resty.Client
  9. baseUrl string
  10. token string
  11. options *Options
  12. }
  13. func NewClient(baseUrl string, token string, opts ...Option) *Client {
  14. options := new(Options)
  15. for _, opt := range opts {
  16. opt(options)
  17. }
  18. restyClient := resty.New().
  19. SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true}).
  20. SetTimeout(time.Duration(options.timeoutSec) * time.Second).
  21. SetBaseURL(baseUrl)
  22. return &Client{
  23. restyClient: restyClient,
  24. baseUrl: baseUrl,
  25. token: token,
  26. options: options,
  27. }
  28. }