github.com/replit/upm@v0.0.0-20240423230255-9ce4fc3ea24c/internal/api/http.go (about) 1 package api 2 3 import ( 4 "fmt" 5 "net/http" 6 ) 7 8 var HttpClient = &UpmHttpClient{} 9 10 type UpmHttpClient struct { 11 http.Client 12 } 13 14 func (c *UpmHttpClient) Do(req *http.Request) (*http.Response, error) { 15 req.Header.Set("User-Agent", "upm (+https://github.com/replit/upm)") 16 resp, err := c.Client.Do(req) 17 if resp == nil && err == nil { 18 panic(fmt.Errorf("no response and no error %v", req)) 19 } 20 21 return resp, err 22 } 23 24 func (c *UpmHttpClient) Get(url string) (*http.Response, error) { 25 req, err := http.NewRequest("GET", url, nil) 26 if err != nil { 27 return &http.Response{}, err 28 } 29 return c.Do(req) 30 }