@cryptotaxi247 / kubo / commits / ea2a35686

fix staticcheck

This commit was moved from ipfs/go-ipfs-http-client@4461a0bb952ce0a05a5bab9728cc64b658375068

Marten Seemann committed May 15, 2021 at 18:21 UTC ea2a35686db523b544245cbaea5592021d0cd163
4 files changed +13 -16
client/httpapi/api.go
+8 -9
@@ -5,7 +5,6 @@ import (
5 "fmt"
6 "io/ioutil"
7 "net/http"
8 - gohttp "net/http"
8 "os"
9 "path/filepath"
10 "strings"
@@ -14,7 +13,7 @@ import (
13 caopts "github.com/ipfs/interface-go-ipfs-core/options"
14 "github.com/mitchellh/go-homedir"
15 ma "github.com/multiformats/go-multiaddr"
17 - manet "github.com/multiformats/go-multiaddr-net"
16 + manet "github.com/multiformats/go-multiaddr/net"
17 )
18
19 const (
@@ -34,7 +33,7 @@ var ErrApiNotFound = errors.New("ipfs api address could not be found")
33 // https://godoc.org/github.com/ipfs/interface-go-ipfs-core#CoreAPI
34 type HttpApi struct {
35 url string
37 - httpcli gohttp.Client
36 + httpcli http.Client
37 Headers http.Header
38 applyGlobal func(*requestBuilder)
39 }
@@ -85,9 +84,9 @@ func ApiAddr(ipfspath string) (ma.Multiaddr, error) {
84
85 // NewApi constructs HttpApi with specified endpoint
86 func NewApi(a ma.Multiaddr) (*HttpApi, error) {
88 - c := &gohttp.Client{
89 - Transport: &gohttp.Transport{
90 - Proxy: gohttp.ProxyFromEnvironment,
87 + c := &http.Client{
88 + Transport: &http.Transport{
89 + Proxy: http.ProxyFromEnvironment,
90 DisableKeepAlives: true,
91 },
92 }
@@ -96,7 +95,7 @@ func NewApi(a ma.Multiaddr) (*HttpApi, error) {
95 }
96
97 // NewApiWithClient constructs HttpApi with specified endpoint and custom http client
99 -func NewApiWithClient(a ma.Multiaddr, c *gohttp.Client) (*HttpApi, error) {
98 +func NewApiWithClient(a ma.Multiaddr, c *http.Client) (*HttpApi, error) {
99 _, url, err := manet.DialArgs(a)
100 if err != nil {
101 return nil, err
@@ -112,7 +111,7 @@ func NewApiWithClient(a ma.Multiaddr, c *gohttp.Client) (*HttpApi, error) {
111 return NewURLApiWithClient(url, c)
112 }
113
115 -func NewURLApiWithClient(url string, c *gohttp.Client) (*HttpApi, error) {
114 +func NewURLApiWithClient(url string, c *http.Client) (*HttpApi, error) {
115 api := &HttpApi{
116 url: url,
117 httpcli: *c,
@@ -121,7 +120,7 @@ func NewURLApiWithClient(url string, c *gohttp.Client) (*HttpApi, error) {
120 }
121
122 // We don't support redirects.
124 - api.httpcli.CheckRedirect = func(_ *gohttp.Request, _ []*gohttp.Request) error {
123 + api.httpcli.CheckRedirect = func(_ *http.Request, _ []*http.Request) error {
124 return fmt.Errorf("unexpected redirect")
125 }
126 return api, nil
client/httpapi/api_test.go
+3 -4
@@ -4,7 +4,6 @@ import (
4 "context"
5 "io/ioutil"
6 "net/http"
7 - gohttp "net/http"
7 "net/http/httptest"
8 "os"
9 "strconv"
@@ -163,9 +162,9 @@ func (NodeProvider) makeAPISwarm(ctx context.Context, fullIdentity bool, n int)
162 return
163 }
164
166 - c := &gohttp.Client{
167 - Transport: &gohttp.Transport{
168 - Proxy: gohttp.ProxyFromEnvironment,
165 + c := &http.Client{
166 + Transport: &http.Transport{
167 + Proxy: http.ProxyFromEnvironment,
168 DisableKeepAlives: true,
169 DisableCompression: true,
170 },
client/httpapi/object.go
+1 -2
@@ -10,7 +10,6 @@ import (
10 "github.com/ipfs/go-cid"
11 ipld "github.com/ipfs/go-ipld-format"
12 "github.com/ipfs/go-merkledag"
13 - dag "github.com/ipfs/go-merkledag"
13 ft "github.com/ipfs/go-unixfs"
14 "github.com/ipfs/interface-go-ipfs-core"
15 caopts "github.com/ipfs/interface-go-ipfs-core/options"
@@ -32,7 +31,7 @@ func (api *ObjectAPI) New(ctx context.Context, opts ...caopts.ObjectNewOption) (
31 var n ipld.Node
32 switch options.Type {
33 case "empty":
35 - n = new(dag.ProtoNode)
34 + n = new(merkledag.ProtoNode)
35 case "unixfs-dir":
36 n = ft.EmptyDirNode()
37 default:
client/httpapi/pin.go
+1 -1
@@ -93,7 +93,7 @@ func (api *PinAPI) IsPinned(ctx context.Context, p path.Path, opts ...caopts.Pin
93 if err != nil {
94 // TODO: This error-type discrimination based on sub-string matching is brittle.
95 // It is addressed by this open issue: https://github.com/ipfs/go-ipfs/issues/7563
96 - if strings.Index(err.Error(), "is not pinned") != -1 {
96 + if strings.Contains(err.Error(), "is not pinned") {
97 return "", false, nil
98 }
99 return "", false, err