Upgrade to go 1.19 and update dependencies (#3069)

* Update to go 1.19
* Update dependencies
* Update cross-compile script
* Add missing targets to cross-compile-all
* Update cache action to remove warning
This commit is contained in:
WithoutPants
2022-11-04 13:41:26 +11:00
committed by GitHub
parent f25881a3bf
commit bba7c23957
939 changed files with 101336 additions and 43819 deletions

View File

@@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"os"
@@ -155,7 +156,7 @@ func (s *HTTPSender) SendWithTimeout(req *http.Request, timeout time.Duration) (
s.l.Debugf("astikit: sending %s", nr)
if resp, err = s.client.Do(req); err != nil {
// Retry if error is temporary, stop here otherwise
if netError, ok := err.(net.Error); !ok || !netError.Temporary() {
if netError, ok := err.(net.Error); !ok || !netError.Timeout() {
err = fmt.Errorf("astikit: sending %s failed: %w", nr, err)
return
}
@@ -184,14 +185,20 @@ func (s *HTTPSender) SendWithTimeout(req *http.Request, timeout time.Duration) (
return
}
type HTTPSenderHeaderFunc func(h http.Header)
type HTTPSenderStatusCodeFunc func(code int) error
// HTTPSendJSONOptions represents SendJSON options
type HTTPSendJSONOptions struct {
BodyError interface{}
BodyIn interface{}
BodyOut interface{}
Headers map[string]string
Method string
URL string
BodyError interface{}
BodyIn interface{}
BodyOut interface{}
HeadersIn map[string]string
HeadersOut HTTPSenderHeaderFunc
Method string
StatusCodeFunc HTTPSenderStatusCodeFunc
URL string
}
// SendJSON sends a new JSON HTTP request
@@ -215,7 +222,7 @@ func (s *HTTPSender) SendJSON(o HTTPSendJSONOptions) (err error) {
}
// Add headers
for k, v := range o.Headers {
for k, v := range o.HeadersIn {
req.Header.Set(k, v)
}
@@ -227,8 +234,17 @@ func (s *HTTPSender) SendJSON(o HTTPSendJSONOptions) (err error) {
}
defer resp.Body.Close()
// Process headers
if o.HeadersOut != nil {
o.HeadersOut(resp.Header)
}
// Process status code
if code := resp.StatusCode; code < 200 || code > 299 {
fn := HTTPSenderDefaultStatusCodeFunc
if o.StatusCodeFunc != nil {
fn = o.StatusCodeFunc
}
if err = fn(resp.StatusCode); err != nil {
// Try unmarshaling error
if o.BodyError != nil {
if err2 := json.NewDecoder(resp.Body).Decode(o.BodyError); err2 == nil {
@@ -238,20 +254,35 @@ func (s *HTTPSender) SendJSON(o HTTPSendJSONOptions) (err error) {
}
// Default error
err = fmt.Errorf("astikit: invalid status code %d", code)
err = fmt.Errorf("astikit: validating status code %d failed: %w", resp.StatusCode, err)
return
}
// Unmarshal body out
if o.BodyOut != nil {
if err = json.NewDecoder(resp.Body).Decode(o.BodyOut); err != nil {
err = fmt.Errorf("astikit: unmarshaling failed: %w", err)
// Read all
var b []byte
if b, err = ioutil.ReadAll(resp.Body); err != nil {
err = fmt.Errorf("astikit: reading all failed: %w", err)
return
}
// Unmarshal
if err = json.Unmarshal(b, o.BodyOut); err != nil {
err = fmt.Errorf("astikit: unmarshaling failed: %w (json: %s)", err, b)
return
}
}
return
}
func HTTPSenderDefaultStatusCodeFunc(code int) error {
if code < 200 || code > 299 {
return errors.New("astikit: status code should be between 200 and 299")
}
return nil
}
// HTTPResponseFunc is a func that can process an $http.Response
type HTTPResponseFunc func(resp *http.Response) error
@@ -380,6 +411,7 @@ func (d *HTTPDownloader) download(ctx context.Context, srcs []HTTPDownloaderSrc,
}
// Do
//nolint:errcheck
d.l.Do(func() {
// Task is done
defer wg.Done()