Skip to content
Draft
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
23 changes: 14 additions & 9 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
version: "2"
linters:
default: standard
enable:
- stylecheck

linters-settings:
stylecheck:
checks:
- all
- '-ST1003'
dot-import-whitelist:
- github.com/ipfs/kubo/test/cli/testutils
- staticcheck
- unconvert
- usestdlibvars
disable:
- errcheck
settings:
staticcheck:
checks:
- all
- -ST1003
dot-import-whitelist:
- github.com/ipfs/kubo/test/cli/testutils
1 change: 1 addition & 0 deletions assets/assets.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package assets provides embedded asset files for kubo.
package assets

import (
Expand Down
1 change: 1 addition & 0 deletions client/rpc/api.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package rpc provides an RPC client implementation for the kubo HTTP API.
package rpc

import (
Expand Down
2 changes: 1 addition & 1 deletion client/rpc/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func Test_NewURLApiWithClient_With_Headers(t *testing.T) {
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
val := r.Header.Get(headerToTest)
if val != expectedHeaderValue {
w.WriteHeader(400)
w.WriteHeader(http.StatusBadRequest)
return
}
http.ServeContent(w, r, "", time.Now(), strings.NewReader("test"))
Expand Down
1 change: 1 addition & 0 deletions client/rpc/auth/auth.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package auth provides HTTP authentication utilities for the RPC client.
package auth

import "net/http"
Expand Down
2 changes: 1 addition & 1 deletion client/rpc/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (r *Response) decode(dec interface{}) error {

func (r *Request) Send(c *http.Client) (*Response, error) {
url := r.getURL()
req, err := http.NewRequest("POST", url, r.Body)
req, err := http.NewRequest(http.MethodPost, url, r.Body)
if err != nil {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/ipfs/kubo/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,10 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
}
defer fetcher.Close()

if migrationCfg.Keep == "cache" {
switch migrationCfg.Keep {
case "cache":
cacheMigrations = true
} else if migrationCfg.Keep == "pin" {
case "pin":
pinMigrations = true
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/ipfs/kubo/start.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// cmd/ipfs/kubo implements the primary CLI binary for kubo
// Package kubo implements the primary CLI binary for kubo
package kubo

import (
Expand Down
1 change: 1 addition & 0 deletions cmd/ipfs/util/signal.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//go:build !wasm
// +build !wasm

// Package util provides utility functions for the IPFS CLI.
package util

import (
Expand Down
1 change: 1 addition & 0 deletions commands/context.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package commands implements IPFS commands.
package commands

import (
Expand Down
6 changes: 3 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// package config implements the ipfs config file datastructures and utilities.
// Package config implements the ipfs config file datastructures and utilities.
package config

import (
Expand Down Expand Up @@ -141,7 +141,7 @@ func ToMap(conf *Config) (map[string]interface{}, error) {
return m, nil
}

// Convert config to a map, without using encoding/json, since
// ReflectToMap converts config to a map, without using encoding/json, since
// zero/empty/'omitempty' fields are excluded by encoding/json during
// marshaling.
func ReflectToMap(conf interface{}) interface{} {
Expand Down Expand Up @@ -222,7 +222,7 @@ func (c *Config) Clone() (*Config, error) {
return &newConfig, nil
}

// Check if the provided key is present in the structure.
// CheckKey checks if the provided key is present in the structure.
func CheckKey(key string) error {
conf := Config{}

Expand Down
6 changes: 3 additions & 3 deletions config/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ func (r *RouterParser) UnmarshalJSON(b []byte) error {
return err
}

r.Router.Type = out.Type
r.Router.Parameters = p
r.Type = out.Type
r.Parameters = p

return nil
}

// Type is the routing type.
// RouterType is the routing type.
// Depending of the type we need to instantiate different Routing implementations.
type RouterType string

Expand Down
1 change: 1 addition & 0 deletions config/serialize/serialize.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package fsrepo provides configuration serialization utilities.
package fsrepo

import (
Expand Down
2 changes: 1 addition & 1 deletion core/commands/cat.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var CatCmd = &cmds.Command{
return err
}

readers, length, err := cat(req.Context, api, req.Arguments, int64(offset), int64(max))
readers, length, err := cat(req.Context, api, req.Arguments, offset, max)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion core/commands/cid.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ var codecsCmd = &cmds.Command{
continue
}
}
res = append(res, CodeAndName{int(code), mc.Code(code).String()})
res = append(res, CodeAndName{int(code), code.String()})
}
}
return cmds.EmitOnce(resp, res)
Expand Down
1 change: 1 addition & 0 deletions core/commands/cmdenv/env.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package cmdenv provides the environment for executing IPFS commands.
package cmdenv

import (
Expand Down
1 change: 1 addition & 0 deletions core/commands/cmdutils/utils.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package cmdutils provides utilities for kubo commands.
package cmdutils

import (
Expand Down
1 change: 1 addition & 0 deletions core/commands/dag/dag.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package dagcmd provides IPFS DAG manipulation commands.
package dagcmd

import (
Expand Down
1 change: 1 addition & 0 deletions core/commands/e/error.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package e provides error utilities for IPFS commands.
package e

import (
Expand Down
30 changes: 15 additions & 15 deletions core/commands/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,16 @@ var filesStatCmd = &cmds.Command{
}

s, _ := statGetFormatOptions(req)
s = strings.Replace(s, "<hash>", out.Hash, -1)
s = strings.Replace(s, "<size>", fmt.Sprintf("%d", out.Size), -1)
s = strings.Replace(s, "<cumulsize>", fmt.Sprintf("%d", out.CumulativeSize), -1)
s = strings.Replace(s, "<childs>", fmt.Sprintf("%d", out.Blocks), -1)
s = strings.Replace(s, "<type>", out.Type, -1)
s = strings.Replace(s, "<mode>", mode, -1)
s = strings.Replace(s, "<mode-octal>", modeo, -1)
s = strings.Replace(s, "<mtime>", mtime, -1)
s = strings.Replace(s, "<mtime-secs>", mtimes, -1)
s = strings.Replace(s, "<mtime-nsecs>", mtimens, -1)
s = strings.ReplaceAll(s, "<hash>", out.Hash)
s = strings.ReplaceAll(s, "<size>", fmt.Sprintf("%d", out.Size))
s = strings.ReplaceAll(s, "<cumulsize>", fmt.Sprintf("%d", out.CumulativeSize))
s = strings.ReplaceAll(s, "<childs>", fmt.Sprintf("%d", out.Blocks))
s = strings.ReplaceAll(s, "<type>", out.Type)
s = strings.ReplaceAll(s, "<mode>", mode)
s = strings.ReplaceAll(s, "<mode-octal>", modeo)
s = strings.ReplaceAll(s, "<mtime>", mtime)
s = strings.ReplaceAll(s, "<mtime-secs>", mtimes)
s = strings.ReplaceAll(s, "<mtime-nsecs>", mtimens)

fmt.Fprintln(w, s)

Expand Down Expand Up @@ -785,11 +785,11 @@ Examples:
return err
}

if int64(offset) > filen {
if offset > filen {
return fmt.Errorf("offset was past end of file (%d > %d)", offset, filen)
}

_, err = rfd.Seek(int64(offset), io.SeekStart)
_, err = rfd.Seek(offset, io.SeekStart)
if err != nil {
return err
}
Expand All @@ -800,7 +800,7 @@ Examples:
if count < 0 {
return fmt.Errorf("cannot specify negative 'count'")
}
r = io.LimitReader(r, int64(count))
r = io.LimitReader(r, count)
}
return res.Emit(r)
},
Expand Down Expand Up @@ -1049,7 +1049,7 @@ See '--to-files' in 'ipfs add --help' for more information.
return fmt.Errorf("cannot have negative byte count")
}

_, err = wfd.Seek(int64(offset), io.SeekStart)
_, err = wfd.Seek(offset, io.SeekStart)
if err != nil {
flog.Error("seekfail: ", err)
return err
Expand All @@ -1061,7 +1061,7 @@ See '--to-files' in 'ipfs add --help' for more information.
return err
}
if countfound {
r = io.LimitReader(r, int64(count))
r = io.LimitReader(r, count)
}

_, err = io.Copy(wfd, r)
Expand Down
14 changes: 7 additions & 7 deletions core/commands/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ EXAMPLE:
format, found := req.Options[formatOptionName].(string)
if found {
output := format
output = strings.Replace(output, "<id>", out.ID, -1)
output = strings.Replace(output, "<aver>", out.AgentVersion, -1)
output = strings.Replace(output, "<pubkey>", out.PublicKey, -1)
output = strings.Replace(output, "<addrs>", strings.Join(out.Addresses, "\n"), -1)
output = strings.Replace(output, "<protocols>", strings.Join(protocol.ConvertToStrings(out.Protocols), "\n"), -1)
output = strings.Replace(output, "\\n", "\n", -1)
output = strings.Replace(output, "\\t", "\t", -1)
output = strings.ReplaceAll(output, "<id>", out.ID)
output = strings.ReplaceAll(output, "<aver>", out.AgentVersion)
output = strings.ReplaceAll(output, "<pubkey>", out.PublicKey)
output = strings.ReplaceAll(output, "<addrs>", strings.Join(out.Addresses, "\n"))
output = strings.ReplaceAll(output, "<protocols>", strings.Join(protocol.ConvertToStrings(out.Protocols), "\n"))
output = strings.ReplaceAll(output, "\\n", "\n")
output = strings.ReplaceAll(output, "\\t", "\t")
fmt.Fprint(w, output)
} else {
marshaled, err := json.MarshalIndent(out, "", "\t")
Expand Down
1 change: 1 addition & 0 deletions core/commands/keyencode/keyencode.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package keyencode provides key encoding utilities for kubo commands.
package keyencode

import (
Expand Down
3 changes: 2 additions & 1 deletion core/commands/name/ipns.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package name provides IPNS name commands.
package name

import (
Expand Down Expand Up @@ -149,7 +150,7 @@ Resolve the value of a dnslink:
if v.Err != nil && (recursive || v.Err != namesys.ErrResolveRecursion) {
return v.Err
}
if err := res.Emit(&ResolvedPath{v.Path.String()}); err != nil {
if err := res.Emit(&ResolvedPath{v.String()}); err != nil {
return err
}

Expand Down
1 change: 1 addition & 0 deletions core/commands/object/object.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package objectcmd implements IPFS object manipulation commands.
package objectcmd

import (
Expand Down
2 changes: 1 addition & 1 deletion core/commands/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ var p2pCloseCmd = &cmds.Command{
}
}

if !(closeAll || p || l || t) {
if !closeAll && !p && !l && !t {
return errors.New("no matching options given")
}

Expand Down
13 changes: 7 additions & 6 deletions core/commands/pin/pin.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package pin implements IPFS pinning commands.
package pin

import (
Expand Down Expand Up @@ -387,7 +388,7 @@ Example:
lgcList := map[string]PinLsType{}
if !stream {
emit = func(v PinLsOutputWrapper) error {
lgcList[v.PinLsObject.Cid] = PinLsType{Type: v.PinLsObject.Type, Name: v.PinLsObject.Name}
lgcList[v.Cid] = PinLsType{Type: v.Type, Name: v.Name}
return nil
}
} else {
Expand Down Expand Up @@ -432,16 +433,16 @@ Example:

if stream {
if quiet {
fmt.Fprintf(w, "%s\n", out.PinLsObject.Cid)
} else if out.PinLsObject.Name == "" {
fmt.Fprintf(w, "%s %s\n", out.PinLsObject.Cid, out.PinLsObject.Type)
fmt.Fprintf(w, "%s\n", out.Cid)
} else if out.Name == "" {
fmt.Fprintf(w, "%s %s\n", out.Cid, out.Type)
} else {
fmt.Fprintf(w, "%s %s %s\n", out.PinLsObject.Cid, out.PinLsObject.Type, out.PinLsObject.Name)
fmt.Fprintf(w, "%s %s %s\n", out.Cid, out.Type, out.Name)
}
return nil
}

for k, v := range out.PinLsList.Keys {
for k, v := range out.Keys {
if quiet {
fmt.Fprintf(w, "%s\n", k)
} else if v.Name == "" {
Expand Down
4 changes: 2 additions & 2 deletions core/commands/pin/remotepin.go
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ type PinCount struct {
Failed int
}

// Struct returned by ipfs pin remote service ls --enc=json | jq
// PinServicesList is the struct returned by ipfs pin remote service ls --enc=json | jq
type PinServicesList struct {
RemoteServices []ServiceDetails
}
Expand Down Expand Up @@ -772,7 +772,7 @@ func getRemotePinServiceInfo(env cmds.Environment, name string) (endpoint, key s

func normalizeEndpoint(endpoint string) (string, error) {
uri, err := neturl.ParseRequestURI(endpoint)
if err != nil || !(uri.Scheme == "http" || uri.Scheme == "https") {
if err != nil || (uri.Scheme != "http" && uri.Scheme != "https") {
return "", fmt.Errorf("service endpoint must be a valid HTTP URL")
}

Expand Down
8 changes: 4 additions & 4 deletions core/commands/refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func (rw *RefWriter) visit(c cid.Cid, depth int) (bool, bool) {
return !atMaxDepth, !ok
}

// Write one edge
// WriteEdge writes one edge
func (rw *RefWriter) WriteEdge(from, to cid.Cid, linkname string, enc cidenc.Encoder) error {
if rw.Ctx != nil {
select {
Expand All @@ -334,9 +334,9 @@ func (rw *RefWriter) WriteEdge(from, to cid.Cid, linkname string, enc cidenc.Enc
switch {
case rw.PrintFmt != "":
s = rw.PrintFmt
s = strings.Replace(s, "<src>", enc.Encode(from), -1)
s = strings.Replace(s, "<dst>", enc.Encode(to), -1)
s = strings.Replace(s, "<linkname>", linkname, -1)
s = strings.ReplaceAll(s, "<src>", enc.Encode(from))
s = strings.ReplaceAll(s, "<dst>", enc.Encode(to))
s = strings.ReplaceAll(s, "<linkname>", linkname)
default:
s += enc.Encode(to)
}
Expand Down
2 changes: 1 addition & 1 deletion core/commands/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ func escapeDhtKey(s string) (string, error) {
parts := strings.Split(s, "/")
if len(parts) != 3 ||
parts[0] != "" ||
!(parts[1] == "ipns" || parts[1] == "pk") {
(parts[1] != "ipns" && parts[1] != "pk") {
return "", errors.New("invalid key")
}

Expand Down
Loading
Loading