resty.go raw

   1  // Copyright (c) 2015-2024 Jeevanandam M (jeeva@myjeeva.com), All rights reserved.
   2  // resty source code and usage is governed by a MIT style
   3  // license that can be found in the LICENSE file.
   4  
   5  // Package resty provides Simple HTTP and REST client library for Go.
   6  package resty
   7  
   8  import (
   9  	"net"
  10  	"net/http"
  11  	"net/http/cookiejar"
  12  
  13  	"golang.org/x/net/publicsuffix"
  14  )
  15  
  16  // Version # of resty
  17  const Version = "2.17.1"
  18  
  19  // New method creates a new Resty client.
  20  func New() *Client {
  21  	cookieJar, _ := cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List})
  22  	return createClient(&http.Client{
  23  		Jar: cookieJar,
  24  	})
  25  }
  26  
  27  // NewWithClient method creates a new Resty client with given [http.Client].
  28  func NewWithClient(hc *http.Client) *Client {
  29  	return createClient(hc)
  30  }
  31  
  32  // NewWithLocalAddr method creates a new Resty client with the given Local Address.
  33  // to dial from.
  34  func NewWithLocalAddr(localAddr net.Addr) *Client {
  35  	cookieJar, _ := cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List})
  36  	return createClient(&http.Client{
  37  		Jar:       cookieJar,
  38  		Transport: createTransport(localAddr),
  39  	})
  40  }
  41