github.com/LagrangeDev/LagrangeGo@v0.0.0-20240512064304-ad4a85e10cb4/client/http2/client.go (about)

     1  package http2
     2  
     3  import (
     4  	"errors"
     5  	"io"
     6  	"net"
     7  	"net/http"
     8  	"net/url"
     9  	"time"
    10  
    11  	"golang.org/x/net/http2"
    12  
    13  	"github.com/fumiama/terasu/dns"
    14  	trsh2 "github.com/fumiama/terasu/http2"
    15  )
    16  
    17  func init() {
    18  	dns.SetTimeout(time.Second)
    19  }
    20  
    21  var (
    22  	ErrEmptyHostAddress = errors.New("empty host addr")
    23  )
    24  
    25  var defaultDialer = net.Dialer{
    26  	Timeout: time.Minute,
    27  }
    28  
    29  func SetDefaultClientTimeout(t time.Duration) {
    30  	defaultDialer.Timeout = t
    31  }
    32  
    33  var DefaultClient = http.Client{
    34  	Transport: &http2.Transport{},
    35  }
    36  
    37  var TRSClient = &trsh2.DefaultClient
    38  
    39  func Get(url string) (resp *http.Response, err error) {
    40  	return DefaultClient.Get(url)
    41  }
    42  
    43  func Head(url string) (resp *http.Response, err error) {
    44  	return DefaultClient.Head(url)
    45  }
    46  
    47  func Post(url string, contentType string, body io.Reader) (resp *http.Response, err error) {
    48  	return DefaultClient.Post(url, contentType, body)
    49  }
    50  
    51  func PostForm(url string, data url.Values) (resp *http.Response, err error) {
    52  	return DefaultClient.PostForm(url, data)
    53  }