github.com/bingoohuang/gg@v0.0.0-20240325092523-45da7dee9335/pkg/resty/resty.go (about) 1 // Copyright (c) 2015-2021 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.7.0" 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{Jar: cookieJar}) 23 } 24 25 // NewWithClient method creates a new Resty client with given `http.Client`. 26 func NewWithClient(hc *http.Client) *Client { return createClient(hc) } 27 28 // NewWithLocalAddr method creates a new Resty client with given Local Address to dial from. 29 func NewWithLocalAddr(localAddr net.Addr) *Client { 30 cookieJar, _ := cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List}) 31 return createClient(&http.Client{ 32 Jar: cookieJar, 33 Transport: createTransport(localAddr), 34 }) 35 }