Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

fix staticcheck #143

Merged
merged 1 commit into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"io/ioutil"
"net/http"
gohttp "net/http"
"os"
"path/filepath"
"strings"
Expand All @@ -14,7 +13,7 @@ import (
caopts "github.com/ipfs/interface-go-ipfs-core/options"
"github.com/mitchellh/go-homedir"
ma "github.com/multiformats/go-multiaddr"
manet "github.com/multiformats/go-multiaddr-net"
manet "github.com/multiformats/go-multiaddr/net"
)

const (
Expand All @@ -34,7 +33,7 @@ var ErrApiNotFound = errors.New("ipfs api address could not be found")
// https://godoc.org/github.com/ipfs/interface-go-ipfs-core#CoreAPI
type HttpApi struct {
url string
httpcli gohttp.Client
httpcli http.Client
Headers http.Header
applyGlobal func(*requestBuilder)
}
Expand Down Expand Up @@ -85,9 +84,9 @@ func ApiAddr(ipfspath string) (ma.Multiaddr, error) {

// NewApi constructs HttpApi with specified endpoint
func NewApi(a ma.Multiaddr) (*HttpApi, error) {
c := &gohttp.Client{
Transport: &gohttp.Transport{
Proxy: gohttp.ProxyFromEnvironment,
c := &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
DisableKeepAlives: true,
},
}
Expand All @@ -96,7 +95,7 @@ func NewApi(a ma.Multiaddr) (*HttpApi, error) {
}

// NewApiWithClient constructs HttpApi with specified endpoint and custom http client
func NewApiWithClient(a ma.Multiaddr, c *gohttp.Client) (*HttpApi, error) {
func NewApiWithClient(a ma.Multiaddr, c *http.Client) (*HttpApi, error) {
_, url, err := manet.DialArgs(a)
if err != nil {
return nil, err
Expand All @@ -112,7 +111,7 @@ func NewApiWithClient(a ma.Multiaddr, c *gohttp.Client) (*HttpApi, error) {
return NewURLApiWithClient(url, c)
}

func NewURLApiWithClient(url string, c *gohttp.Client) (*HttpApi, error) {
func NewURLApiWithClient(url string, c *http.Client) (*HttpApi, error) {
api := &HttpApi{
url: url,
httpcli: *c,
Expand All @@ -121,7 +120,7 @@ func NewURLApiWithClient(url string, c *gohttp.Client) (*HttpApi, error) {
}

// We don't support redirects.
api.httpcli.CheckRedirect = func(_ *gohttp.Request, _ []*gohttp.Request) error {
api.httpcli.CheckRedirect = func(_ *http.Request, _ []*http.Request) error {
return fmt.Errorf("unexpected redirect")
}
return api, nil
Expand Down
7 changes: 3 additions & 4 deletions api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"io/ioutil"
"net/http"
gohttp "net/http"
"net/http/httptest"
"os"
"strconv"
Expand Down Expand Up @@ -163,9 +162,9 @@ func (NodeProvider) makeAPISwarm(ctx context.Context, fullIdentity bool, n int)
return
}

c := &gohttp.Client{
Transport: &gohttp.Transport{
Proxy: gohttp.ProxyFromEnvironment,
c := &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
DisableKeepAlives: true,
DisableCompression: true,
},
Expand Down
3 changes: 1 addition & 2 deletions object.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/ipfs/go-cid"
ipld "github.com/ipfs/go-ipld-format"
"github.com/ipfs/go-merkledag"
dag "github.com/ipfs/go-merkledag"
ft "github.com/ipfs/go-unixfs"
"github.com/ipfs/interface-go-ipfs-core"
caopts "github.com/ipfs/interface-go-ipfs-core/options"
Expand All @@ -32,7 +31,7 @@ func (api *ObjectAPI) New(ctx context.Context, opts ...caopts.ObjectNewOption) (
var n ipld.Node
switch options.Type {
case "empty":
n = new(dag.ProtoNode)
n = new(merkledag.ProtoNode)
case "unixfs-dir":
n = ft.EmptyDirNode()
default:
Expand Down
2 changes: 1 addition & 1 deletion pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (api *PinAPI) IsPinned(ctx context.Context, p path.Path, opts ...caopts.Pin
if err != nil {
// TODO: This error-type discrimination based on sub-string matching is brittle.
// It is addressed by this open issue: https://github.com/ipfs/go-ipfs/issues/7563
if strings.Index(err.Error(), "is not pinned") != -1 {
if strings.Contains(err.Error(), "is not pinned") {
return "", false, nil
}
return "", false, err
Expand Down