Skip to content

Commit f12b372

Browse files
authored
style: gofumpt and godot [skip changelog] (#10081)
1 parent b4f4150 commit f12b372

File tree

148 files changed

+449
-433
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+449
-433
lines changed

assets/assets.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
//go:embed init-doc
1818
var Asset embed.FS
1919

20-
// initDocPaths lists the paths for the docs we want to seed during --init
20+
// initDocPaths lists the paths for the docs we want to seed during --init.
2121
var initDocPaths = []string{
2222
gopath.Join("init-doc", "about"),
2323
gopath.Join("init-doc", "readme"),
@@ -28,7 +28,7 @@ var initDocPaths = []string{
2828
gopath.Join("init-doc", "ping"),
2929
}
3030

31-
// SeedInitDocs adds the list of embedded init documentation to the passed node, pins it and returns the root key
31+
// SeedInitDocs adds the list of embedded init documentation to the passed node, pins it and returns the root key.
3232
func SeedInitDocs(nd *core.IpfsNode) (cid.Cid, error) {
3333
return addAssetList(nd, initDocPaths)
3434
}

client/rpc/api.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type HttpApi struct {
4848
// IPFS daemon
4949
//
5050
// Daemon api address is pulled from the $IPFS_PATH/api file.
51-
// If $IPFS_PATH env var is not present, it defaults to ~/.ipfs
51+
// If $IPFS_PATH env var is not present, it defaults to ~/.ipfs.
5252
func NewLocalApi() (*HttpApi, error) {
5353
baseDir := os.Getenv(EnvDir)
5454
if baseDir == "" {
@@ -59,7 +59,7 @@ func NewLocalApi() (*HttpApi, error) {
5959
}
6060

6161
// NewPathApi constructs new HttpApi by pulling api address from specified
62-
// ipfspath. Api file should be located at $ipfspath/api
62+
// ipfspath. Api file should be located at $ipfspath/api.
6363
func NewPathApi(ipfspath string) (*HttpApi, error) {
6464
a, err := ApiAddr(ipfspath)
6565
if err != nil {
@@ -71,7 +71,7 @@ func NewPathApi(ipfspath string) (*HttpApi, error) {
7171
return NewApi(a)
7272
}
7373

74-
// ApiAddr reads api file in specified ipfs path
74+
// ApiAddr reads api file in specified ipfs path.
7575
func ApiAddr(ipfspath string) (ma.Multiaddr, error) {
7676
baseDir, err := homedir.Expand(ipfspath)
7777
if err != nil {
@@ -88,7 +88,7 @@ func ApiAddr(ipfspath string) (ma.Multiaddr, error) {
8888
return ma.NewMultiaddr(strings.TrimSpace(string(api)))
8989
}
9090

91-
// NewApi constructs HttpApi with specified endpoint
91+
// NewApi constructs HttpApi with specified endpoint.
9292
func NewApi(a ma.Multiaddr) (*HttpApi, error) {
9393
c := &http.Client{
9494
Transport: &http.Transport{
@@ -100,7 +100,7 @@ func NewApi(a ma.Multiaddr) (*HttpApi, error) {
100100
return NewApiWithClient(a, c)
101101
}
102102

103-
// NewApiWithClient constructs HttpApi with specified endpoint and custom http client
103+
// NewApiWithClient constructs HttpApi with specified endpoint and custom http client.
104104
func NewApiWithClient(a ma.Multiaddr, c *http.Client) (*HttpApi, error) {
105105
_, url, err := manet.DialArgs(a)
106106
if err != nil {

client/rpc/apifile.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/ipfs/go-cid"
1313
)
1414

15-
const forwardSeekLimit = 1 << 14 //16k
15+
const forwardSeekLimit = 1 << 14 // 16k
1616

1717
func (api *UnixfsAPI) Get(ctx context.Context, p path.Path) (files.Node, error) {
1818
if p.Mutable() { // use resolved path in case we are dealing with IPNS / MFS
@@ -107,11 +107,11 @@ func (f *apiFile) Seek(offset int64, whence int) (int64, error) {
107107
case io.SeekCurrent:
108108
offset = f.at + offset
109109
}
110-
if f.at == offset { //noop
110+
if f.at == offset { // noop
111111
return offset, nil
112112
}
113113

114-
if f.at < offset && offset-f.at < forwardSeekLimit { //forward skip
114+
if f.at < offset && offset-f.at < forwardSeekLimit { // forward skip
115115
r, err := io.CopyN(io.Discard, f.r.Output, offset-f.at)
116116

117117
f.at += r
@@ -246,7 +246,6 @@ func (api *UnixfsAPI) getDir(ctx context.Context, p path.Path, size int64) (file
246246
resp, err := api.core().Request("ls", p.String()).
247247
Option("resolve-size", true).
248248
Option("stream", true).Send(ctx)
249-
250249
if err != nil {
251250
return nil, err
252251
}
@@ -266,5 +265,7 @@ func (api *UnixfsAPI) getDir(ctx context.Context, p path.Path, size int64) (file
266265
return d, nil
267266
}
268267

269-
var _ files.File = &apiFile{}
270-
var _ files.Directory = &apiDir{}
268+
var (
269+
_ files.File = &apiFile{}
270+
_ files.Directory = &apiDir{}
271+
)

client/rpc/block.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (api *BlockAPI) Get(ctx context.Context, p path.Path) (io.Reader, error) {
8383
return nil, parseErrNotFoundWithFallbackToError(resp.Error)
8484
}
8585

86-
//TODO: make get return ReadCloser to avoid copying
86+
// TODO: make get return ReadCloser to avoid copying
8787
defer resp.Close()
8888
b := new(bytes.Buffer)
8989
if _, err := io.Copy(b, resp.Output); err != nil {

client/rpc/dag.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ import (
1414
multicodec "github.com/multiformats/go-multicodec"
1515
)
1616

17-
type httpNodeAdder HttpApi
18-
type HttpDagServ httpNodeAdder
19-
type pinningHttpNodeAdder httpNodeAdder
17+
type (
18+
httpNodeAdder HttpApi
19+
HttpDagServ httpNodeAdder
20+
pinningHttpNodeAdder httpNodeAdder
21+
)
2022

2123
func (api *HttpDagServ) Get(ctx context.Context, c cid.Cid) (format.Node, error) {
2224
r, err := api.core().Block().Get(ctx, path.IpldPath(c))
@@ -114,7 +116,7 @@ func (api *HttpDagServ) Pinning() format.NodeAdder {
114116
}
115117

116118
func (api *HttpDagServ) Remove(ctx context.Context, c cid.Cid) error {
117-
return api.core().Block().Rm(ctx, path.IpldPath(c)) //TODO: should we force rm?
119+
return api.core().Block().Rm(ctx, path.IpldPath(c)) // TODO: should we force rm?
118120
}
119121

120122
func (api *HttpDagServ) RemoveMany(ctx context.Context, cids []cid.Cid) error {

client/rpc/errors.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func parseErrNotFound(msg string) (error, bool) {
6868
// Assume CIDs break on:
6969
// - Whitespaces: " \t\n\r\v\f"
7070
// - Semicolon: ";" this is to parse ipld.ErrNotFound wrapped in multierr
71-
// - Double Quotes: "\"" this is for parsing %q and %#v formating
71+
// - Double Quotes: "\"" this is for parsing %q and %#v formating.
7272
const cidBreakSet = " \t\n\r\v\f;\""
7373

7474
func parseIPLDErrNotFound(msg string) (error, bool) {
@@ -139,7 +139,7 @@ func parseIPLDErrNotFound(msg string) (error, bool) {
139139
// This is a simple error type that just return msg as Error().
140140
// But that also match ipld.ErrNotFound when called with Is(err).
141141
// That is needed to keep compatiblity with code that use string.Contains(err.Error(), "blockstore: block not found")
142-
// and code using ipld.ErrNotFound
142+
// and code using ipld.ErrNotFound.
143143
type blockstoreNotFoundMatchingIPLDErrNotFound struct {
144144
msg string
145145
}

client/rpc/object.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (api *ObjectAPI) Data(ctx context.Context, p path.Path) (io.Reader, error)
8787
return nil, resp.Error
8888
}
8989

90-
//TODO: make Data return ReadCloser to avoid copying
90+
// TODO: make Data return ReadCloser to avoid copying
9191
defer resp.Close()
9292
b := new(bytes.Buffer)
9393
if _, err := io.Copy(b, resp.Output); err != nil {

client/rpc/path.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func (api *HttpApi) ResolvePath(ctx context.Context, p path.Path) (path.Resolved
1515
RemPath string
1616
}
1717

18-
//TODO: this is hacky, fixing https://github.com/ipfs/go-ipfs/issues/5703 would help
18+
// TODO: this is hacky, fixing https://github.com/ipfs/go-ipfs/issues/5703 would help
1919

2020
var err error
2121
if p.Namespace() == "ipns" {

client/rpc/pin.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (api *PinAPI) Ls(ctx context.Context, opts ...caopts.PinLsOption) (<-chan i
112112
}
113113

114114
// IsPinned returns whether or not the given cid is pinned
115-
// and an explanation of why its pinned
115+
// and an explanation of why its pinned.
116116
func (api *PinAPI) IsPinned(ctx context.Context, p path.Path, opts ...caopts.PinIsPinnedOption) (string, bool, error) {
117117
options, err := caopts.PinIsPinnedOptions(opts...)
118118
if err != nil {

client/rpc/pubsub.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ func (api *PubsubAPI) Subscribe(ctx context.Context, topic string, opts ...caopt
152152
}
153153
*/
154154
resp, err := api.core().Request("pubsub/sub", toMultibase([]byte(topic))).Send(ctx)
155-
156155
if err != nil {
157156
return nil, err
158157
}
@@ -207,7 +206,7 @@ func (api *PubsubAPI) core() *HttpApi {
207206
return (*HttpApi)(api)
208207
}
209208

210-
// Encodes bytes into URL-safe multibase that can be sent over HTTP RPC (URL or body)
209+
// Encodes bytes into URL-safe multibase that can be sent over HTTP RPC (URL or body).
211210
func toMultibase(data []byte) string {
212211
mb, _ := mbase.Encode(mbase.Base64url, data)
213212
return mb

client/rpc/response.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (r *Response) Close() error {
5454
return nil
5555
}
5656

57-
// Cancel aborts running request (without draining request body)
57+
// Cancel aborts running request (without draining request body).
5858
func (r *Response) Cancel() error {
5959
if r.Output != nil {
6060
return r.Output.Close()
@@ -63,7 +63,7 @@ func (r *Response) Cancel() error {
6363
return nil
6464
}
6565

66-
// Decode reads request body and decodes it as json
66+
// Decode reads request body and decodes it as json.
6767
func (r *Response) decode(dec interface{}) error {
6868
if r.Error != nil {
6969
return r.Error
@@ -157,7 +157,6 @@ func (r *Request) Send(c *http.Client) (*Response, error) {
157157
}
158158

159159
func (r *Request) getURL() string {
160-
161160
values := make(url.Values)
162161
for _, arg := range r.Args {
163162
values.Add("arg", arg)

client/rpc/routing.go

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ func (api *RoutingAPI) Put(ctx context.Context, key string, value []byte, opts .
4949
Option("allow-offline", cfg.AllowOffline).
5050
FileBody(bytes.NewReader(value)).
5151
Send(ctx)
52-
5352
if err != nil {
5453
return err
5554
}

cmd/ipfs/add_migrations.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"github.com/libp2p/go-libp2p/core/peer"
2020
)
2121

22-
// addMigrations adds any migration downloaded by the fetcher to the IPFS node
22+
// addMigrations adds any migration downloaded by the fetcher to the IPFS node.
2323
func addMigrations(ctx context.Context, node *core.IpfsNode, fetcher migrations.Fetcher, pin bool) error {
2424
var fetchers []migrations.Fetcher
2525
if mf, ok := fetcher.(*migrations.MultiFetcher); ok {
@@ -63,7 +63,7 @@ func addMigrations(ctx context.Context, node *core.IpfsNode, fetcher migrations.
6363
return nil
6464
}
6565

66-
// addMigrationFiles adds the files at paths to IPFS, optionally pinning them
66+
// addMigrationFiles adds the files at paths to IPFS, optionally pinning them.
6767
func addMigrationFiles(ctx context.Context, node *core.IpfsNode, paths []string, pin bool) error {
6868
if len(paths) == 0 {
6969
return nil

cmd/ipfs/daemon.go

+9-11
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const (
7373
enableMultiplexKwd = "enable-mplex-experiment"
7474
agentVersionSuffix = "agent-version-suffix"
7575
// apiAddrKwd = "address-api"
76-
// swarmAddrKwd = "address-swarm"
76+
// swarmAddrKwd = "address-swarm".
7777
)
7878

7979
var daemonCmd = &cmds.Command{
@@ -389,7 +389,7 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
389389
"pubsub": pubsub,
390390
"ipnsps": ipnsps,
391391
},
392-
//TODO(Kubuxu): refactor Online vs Offline by adding Permanent vs Ephemeral
392+
// TODO(Kubuxu): refactor Online vs Offline by adding Permanent vs Ephemeral
393393
}
394394

395395
routingOption, _ := req.Options[routingOptionKwd].(string)
@@ -552,7 +552,7 @@ take effect.
552552
}
553553

554554
// Add ipfs version info to prometheus metrics
555-
var ipfsInfoMetric = promauto.NewGaugeVec(prometheus.GaugeOpts{
555+
ipfsInfoMetric := promauto.NewGaugeVec(prometheus.GaugeOpts{
556556
Name: "ipfs_info",
557557
Help: "IPFS version information.",
558558
}, []string{"version", "commit"})
@@ -607,7 +607,6 @@ take effect.
607607
log.Error("failed to bootstrap (no peers found): consider updating Bootstrap or Peering section of your config")
608608
}
609609
})
610-
611610
}
612611

613612
// Hard deprecation notice if someone still uses IPFS_REUSEPORT
@@ -627,7 +626,7 @@ take effect.
627626
return errs
628627
}
629628

630-
// serveHTTPApi collects options, creates listener, prints status message and starts serving requests
629+
// serveHTTPApi collects options, creates listener, prints status message and starts serving requests.
631630
func serveHTTPApi(req *cmds.Request, cctx *oldcmds.Context) (<-chan error, error) {
632631
cfg, err := cctx.GetConfig()
633632
if err != nil {
@@ -690,7 +689,7 @@ func serveHTTPApi(req *cmds.Request, cctx *oldcmds.Context) (<-chan error, error
690689
gatewayOpt = corehttp.GatewayOption("/ipfs", "/ipns")
691690
}
692691

693-
var opts = []corehttp.ServeOption{
692+
opts := []corehttp.ServeOption{
694693
corehttp.MetricsCollectionOption("api"),
695694
corehttp.MetricsOpenCensusCollectionOption(),
696695
corehttp.MetricsOpenCensusDefaultPrometheusRegistry(),
@@ -752,7 +751,7 @@ func rewriteMaddrToUseLocalhostIfItsAny(maddr ma.Multiaddr) ma.Multiaddr {
752751
}
753752
}
754753

755-
// printSwarmAddrs prints the addresses of the host
754+
// printSwarmAddrs prints the addresses of the host.
756755
func printSwarmAddrs(node *core.IpfsNode) {
757756
if !node.IsOnline {
758757
fmt.Println("Swarm not listening, running in offline mode.")
@@ -781,10 +780,9 @@ func printSwarmAddrs(node *core.IpfsNode) {
781780
for _, addr := range addrs {
782781
fmt.Printf("Swarm announcing %s\n", addr)
783782
}
784-
785783
}
786784

787-
// serveHTTPGateway collects options, creates listener, prints status message and starts serving requests
785+
// serveHTTPGateway collects options, creates listener, prints status message and starts serving requests.
788786
func serveHTTPGateway(req *cmds.Request, cctx *oldcmds.Context) (<-chan error, error) {
789787
cfg, err := cctx.GetConfig()
790788
if err != nil {
@@ -837,7 +835,7 @@ func serveHTTPGateway(req *cmds.Request, cctx *oldcmds.Context) (<-chan error, e
837835
cmdctx := *cctx
838836
cmdctx.Gateway = true
839837

840-
var opts = []corehttp.ServeOption{
838+
opts := []corehttp.ServeOption{
841839
corehttp.MetricsCollectionOption("gateway"),
842840
corehttp.HostnameOption(),
843841
corehttp.GatewayOption("/ipfs", "/ipns"),
@@ -891,7 +889,7 @@ func serveHTTPGateway(req *cmds.Request, cctx *oldcmds.Context) (<-chan error, e
891889
return errc, nil
892890
}
893891

894-
// collects options and opens the fuse mountpoint
892+
// collects options and opens the fuse mountpoint.
895893
func mountFuse(req *cmds.Request, cctx *oldcmds.Context) error {
896894
cfg, err := cctx.GetConfig()
897895
if err != nil {

cmd/ipfs/dnsresolve_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ func makeResolver(t *testing.T, n uint8) *madns.Resolver {
2525
backend := &madns.MockResolver{
2626
IP: map[string][]net.IPAddr{
2727
"example.com": results,
28-
}}
28+
},
29+
}
2930

3031
resolver, err := madns.NewResolver(madns.WithDefaultResolver(backend))
3132
if err != nil {

cmd/ipfs/init.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func checkWritable(dir string) error {
194194

195195
if os.IsNotExist(err) {
196196
// dir doesn't exist, check that we can create it
197-
return os.Mkdir(dir, 0775)
197+
return os.Mkdir(dir, 0o775)
198198
}
199199

200200
if os.IsPermission(err) {

cmd/ipfs/ipfs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var Root = &cmds.Command{
1414
Helptext: commands.Root.Helptext,
1515
}
1616

17-
// commandsClientCmd is the "ipfs commands" command for local cli
17+
// commandsClientCmd is the "ipfs commands" command for local cli.
1818
var commandsClientCmd = commands.CommandsCmd(Root)
1919

2020
// Commands in localCommands should always be run locally (even if daemon is running).

cmd/ipfs/main.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ import (
3939
"go.opentelemetry.io/otel/trace"
4040
)
4141

42-
// log is the command logger
43-
var log = logging.Logger("cmd/ipfs")
44-
var tracer trace.Tracer
42+
// log is the command logger.
43+
var (
44+
log = logging.Logger("cmd/ipfs")
45+
tracer trace.Tracer
46+
)
4547

46-
// declared as a var for testing purposes
48+
// declared as a var for testing purposes.
4749
var dnsResolver = madns.DefaultResolver
4850

4951
const (
@@ -73,7 +75,7 @@ func loadPlugins(repoPath string) (*loader.PluginLoader, error) {
7375
// - if user requests help, print it and exit.
7476
// - run the command invocation
7577
// - output the response
76-
// - if anything fails, print error, maybe with help
78+
// - if anything fails, print error, maybe with help.
7779
func main() {
7880
os.Exit(mainRet())
7981
}

0 commit comments

Comments
 (0)