diff --git a/go.mod b/go.mod index ed1bddc..197bc3a 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,5 @@ module moul.io/http2curl/v2 -go 1.13 +go 1.16 require github.com/tailscale/depaware v0.0.0-20210622194025-720c4b409502 diff --git a/go.sum b/go.sum index 73cc17a..a93ac25 100644 --- a/go.sum +++ b/go.sum @@ -1,13 +1,10 @@ -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pkg/diff v0.0.0-20200914180035-5b29258ca4f7 h1:+/+DxvQaYifJ+grD4klzrS5y+KJXldn/2YTl5JG+vZ8= github.com/pkg/diff v0.0.0-20200914180035-5b29258ca4f7/go.mod h1:zO8QMzTeZd5cpnIkz/Gn6iK0jDfGicM1nynOkkPIl28= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/tailscale/depaware v0.0.0-20210622194025-720c4b409502 h1:34icjjmqJ2HPjrSuJYEkdZ+0ItmGQAQ75cRHIiftIyE= github.com/tailscale/depaware v0.0.0-20210622194025-720c4b409502/go.mod h1:p9lPsd+cx33L3H9nNoecRRxPssFKUwwI50I3pZ0yT+8= @@ -36,7 +33,5 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/http2curl.go b/http2curl.go index df21c19..c28ae4c 100644 --- a/http2curl.go +++ b/http2curl.go @@ -3,7 +3,7 @@ package http2curl import ( "bytes" "fmt" - "io/ioutil" + "io" "net/http" "sort" "strings" @@ -23,7 +23,7 @@ func (c *CurlCommand) String() string { } func bashEscape(str string) string { - return `'` + strings.Replace(str, `'`, `'\''`, -1) + `'` + return `'` + strings.ReplaceAll(str, `'`, `'\''`) + `'` } // GetCurlCommand returns a CurlCommand corresponding to an http.Request @@ -59,7 +59,7 @@ func GetCurlCommand(req *http.Request) (*CurlCommand, error) { return nil, fmt.Errorf("getCurlCommand: buffer read from body error: %w", err) } // reset body for potential re-reads - req.Body = ioutil.NopCloser(bytes.NewBuffer(buff.Bytes())) + req.Body = io.NopCloser(bytes.NewBuffer(buff.Bytes())) if len(buff.String()) > 0 { bodyEscaped := bashEscape(buff.String()) command.append("-d", bodyEscaped) diff --git a/http2curl_test.go b/http2curl_test.go index 544dbca..7195028 100644 --- a/http2curl_test.go +++ b/http2curl_test.go @@ -3,7 +3,7 @@ package http2curl import ( "bytes" "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/url" @@ -18,7 +18,7 @@ func ExampleGetCurlCommand() { form.Add("name", "Hudson") body := form.Encode() - req, _ := http.NewRequest(http.MethodPost, "http://foo.com/cats", ioutil.NopCloser(bytes.NewBufferString(body))) + req, _ := http.NewRequest(http.MethodPost, "http://foo.com/cats", io.NopCloser(bytes.NewBufferString(body))) req.Header.Set("API_KEY", "123") command, _ := GetCurlCommand(req) @@ -149,7 +149,7 @@ func BenchmarkGetCurlCommand(b *testing.B) { for i := 0; i <= b.N; i++ { form.Add("number", strconv.Itoa(i)) body := form.Encode() - req, _ := http.NewRequest(http.MethodPost, "http://foo.com", ioutil.NopCloser(bytes.NewBufferString(body))) + req, _ := http.NewRequest(http.MethodPost, "http://foo.com", io.NopCloser(bytes.NewBufferString(body))) _, err := GetCurlCommand(req) if err != nil { panic(err) @@ -172,7 +172,7 @@ func TestGetCurlCommand_serverSide(t *testing.T) { t.Error(err) } defer resp.Body.Close() - data, err := ioutil.ReadAll(resp.Body) + data, err := io.ReadAll(resp.Body) if err != nil { t.Error(err) }