Skip to content

Commit

Permalink
style: gofumpt and godot [skip changelog] (#10081)
Browse files Browse the repository at this point in the history
  • Loading branch information
kehiy authored Aug 17, 2023
1 parent b4f4150 commit f12b372
Show file tree
Hide file tree
Showing 148 changed files with 449 additions and 433 deletions.
4 changes: 2 additions & 2 deletions assets/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
//go:embed init-doc
var Asset embed.FS

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

// SeedInitDocs adds the list of embedded init documentation to the passed node, pins it and returns the root key
// SeedInitDocs adds the list of embedded init documentation to the passed node, pins it and returns the root key.
func SeedInitDocs(nd *core.IpfsNode) (cid.Cid, error) {
return addAssetList(nd, initDocPaths)
}
Expand Down
10 changes: 5 additions & 5 deletions client/rpc/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type HttpApi struct {
// IPFS daemon
//
// Daemon api address is pulled from the $IPFS_PATH/api file.
// If $IPFS_PATH env var is not present, it defaults to ~/.ipfs
// If $IPFS_PATH env var is not present, it defaults to ~/.ipfs.
func NewLocalApi() (*HttpApi, error) {
baseDir := os.Getenv(EnvDir)
if baseDir == "" {
Expand All @@ -59,7 +59,7 @@ func NewLocalApi() (*HttpApi, error) {
}

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

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

// NewApi constructs HttpApi with specified endpoint
// NewApi constructs HttpApi with specified endpoint.
func NewApi(a ma.Multiaddr) (*HttpApi, error) {
c := &http.Client{
Transport: &http.Transport{
Expand All @@ -100,7 +100,7 @@ func NewApi(a ma.Multiaddr) (*HttpApi, error) {
return NewApiWithClient(a, c)
}

// NewApiWithClient constructs HttpApi with specified endpoint and custom http client
// NewApiWithClient constructs HttpApi with specified endpoint and custom http client.
func NewApiWithClient(a ma.Multiaddr, c *http.Client) (*HttpApi, error) {
_, url, err := manet.DialArgs(a)
if err != nil {
Expand Down
13 changes: 7 additions & 6 deletions client/rpc/apifile.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/ipfs/go-cid"
)

const forwardSeekLimit = 1 << 14 //16k
const forwardSeekLimit = 1 << 14 // 16k

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

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

f.at += r
Expand Down Expand Up @@ -246,7 +246,6 @@ func (api *UnixfsAPI) getDir(ctx context.Context, p path.Path, size int64) (file
resp, err := api.core().Request("ls", p.String()).
Option("resolve-size", true).
Option("stream", true).Send(ctx)

if err != nil {
return nil, err
}
Expand All @@ -266,5 +265,7 @@ func (api *UnixfsAPI) getDir(ctx context.Context, p path.Path, size int64) (file
return d, nil
}

var _ files.File = &apiFile{}
var _ files.Directory = &apiDir{}
var (
_ files.File = &apiFile{}
_ files.Directory = &apiDir{}
)
2 changes: 1 addition & 1 deletion client/rpc/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (api *BlockAPI) Get(ctx context.Context, p path.Path) (io.Reader, error) {
return nil, parseErrNotFoundWithFallbackToError(resp.Error)
}

//TODO: make get return ReadCloser to avoid copying
// TODO: make get return ReadCloser to avoid copying
defer resp.Close()
b := new(bytes.Buffer)
if _, err := io.Copy(b, resp.Output); err != nil {
Expand Down
10 changes: 6 additions & 4 deletions client/rpc/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import (
multicodec "github.com/multiformats/go-multicodec"
)

type httpNodeAdder HttpApi
type HttpDagServ httpNodeAdder
type pinningHttpNodeAdder httpNodeAdder
type (
httpNodeAdder HttpApi
HttpDagServ httpNodeAdder
pinningHttpNodeAdder httpNodeAdder
)

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

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

func (api *HttpDagServ) RemoveMany(ctx context.Context, cids []cid.Cid) error {
Expand Down
4 changes: 2 additions & 2 deletions client/rpc/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func parseErrNotFound(msg string) (error, bool) {
// Assume CIDs break on:
// - Whitespaces: " \t\n\r\v\f"
// - Semicolon: ";" this is to parse ipld.ErrNotFound wrapped in multierr
// - Double Quotes: "\"" this is for parsing %q and %#v formating
// - Double Quotes: "\"" this is for parsing %q and %#v formating.
const cidBreakSet = " \t\n\r\v\f;\""

func parseIPLDErrNotFound(msg string) (error, bool) {
Expand Down Expand Up @@ -139,7 +139,7 @@ func parseIPLDErrNotFound(msg string) (error, bool) {
// This is a simple error type that just return msg as Error().
// But that also match ipld.ErrNotFound when called with Is(err).
// That is needed to keep compatiblity with code that use string.Contains(err.Error(), "blockstore: block not found")
// and code using ipld.ErrNotFound
// and code using ipld.ErrNotFound.
type blockstoreNotFoundMatchingIPLDErrNotFound struct {
msg string
}
Expand Down
2 changes: 1 addition & 1 deletion client/rpc/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (api *ObjectAPI) Data(ctx context.Context, p path.Path) (io.Reader, error)
return nil, resp.Error
}

//TODO: make Data return ReadCloser to avoid copying
// TODO: make Data return ReadCloser to avoid copying
defer resp.Close()
b := new(bytes.Buffer)
if _, err := io.Copy(b, resp.Output); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion client/rpc/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (api *HttpApi) ResolvePath(ctx context.Context, p path.Path) (path.Resolved
RemPath string
}

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

var err error
if p.Namespace() == "ipns" {
Expand Down
2 changes: 1 addition & 1 deletion client/rpc/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (api *PinAPI) Ls(ctx context.Context, opts ...caopts.PinLsOption) (<-chan i
}

// IsPinned returns whether or not the given cid is pinned
// and an explanation of why its pinned
// and an explanation of why its pinned.
func (api *PinAPI) IsPinned(ctx context.Context, p path.Path, opts ...caopts.PinIsPinnedOption) (string, bool, error) {
options, err := caopts.PinIsPinnedOptions(opts...)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions client/rpc/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ func (api *PubsubAPI) Subscribe(ctx context.Context, topic string, opts ...caopt
}
*/
resp, err := api.core().Request("pubsub/sub", toMultibase([]byte(topic))).Send(ctx)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -207,7 +206,7 @@ func (api *PubsubAPI) core() *HttpApi {
return (*HttpApi)(api)
}

// Encodes bytes into URL-safe multibase that can be sent over HTTP RPC (URL or body)
// Encodes bytes into URL-safe multibase that can be sent over HTTP RPC (URL or body).
func toMultibase(data []byte) string {
mb, _ := mbase.Encode(mbase.Base64url, data)
return mb
Expand Down
5 changes: 2 additions & 3 deletions client/rpc/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (r *Response) Close() error {
return nil
}

// Cancel aborts running request (without draining request body)
// Cancel aborts running request (without draining request body).
func (r *Response) Cancel() error {
if r.Output != nil {
return r.Output.Close()
Expand All @@ -63,7 +63,7 @@ func (r *Response) Cancel() error {
return nil
}

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

func (r *Request) getURL() string {

values := make(url.Values)
for _, arg := range r.Args {
values.Add("arg", arg)
Expand Down
1 change: 0 additions & 1 deletion client/rpc/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func (api *RoutingAPI) Put(ctx context.Context, key string, value []byte, opts .
Option("allow-offline", cfg.AllowOffline).
FileBody(bytes.NewReader(value)).
Send(ctx)

if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/ipfs/add_migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/libp2p/go-libp2p/core/peer"
)

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

// addMigrationFiles adds the files at paths to IPFS, optionally pinning them
// addMigrationFiles adds the files at paths to IPFS, optionally pinning them.
func addMigrationFiles(ctx context.Context, node *core.IpfsNode, paths []string, pin bool) error {
if len(paths) == 0 {
return nil
Expand Down
20 changes: 9 additions & 11 deletions cmd/ipfs/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const (
enableMultiplexKwd = "enable-mplex-experiment"
agentVersionSuffix = "agent-version-suffix"
// apiAddrKwd = "address-api"
// swarmAddrKwd = "address-swarm"
// swarmAddrKwd = "address-swarm".
)

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

routingOption, _ := req.Options[routingOptionKwd].(string)
Expand Down Expand Up @@ -552,7 +552,7 @@ take effect.
}

// Add ipfs version info to prometheus metrics
var ipfsInfoMetric = promauto.NewGaugeVec(prometheus.GaugeOpts{
ipfsInfoMetric := promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "ipfs_info",
Help: "IPFS version information.",
}, []string{"version", "commit"})
Expand Down Expand Up @@ -607,7 +607,6 @@ take effect.
log.Error("failed to bootstrap (no peers found): consider updating Bootstrap or Peering section of your config")
}
})

}

// Hard deprecation notice if someone still uses IPFS_REUSEPORT
Expand All @@ -627,7 +626,7 @@ take effect.
return errs
}

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

var opts = []corehttp.ServeOption{
opts := []corehttp.ServeOption{
corehttp.MetricsCollectionOption("api"),
corehttp.MetricsOpenCensusCollectionOption(),
corehttp.MetricsOpenCensusDefaultPrometheusRegistry(),
Expand Down Expand Up @@ -752,7 +751,7 @@ func rewriteMaddrToUseLocalhostIfItsAny(maddr ma.Multiaddr) ma.Multiaddr {
}
}

// printSwarmAddrs prints the addresses of the host
// printSwarmAddrs prints the addresses of the host.
func printSwarmAddrs(node *core.IpfsNode) {
if !node.IsOnline {
fmt.Println("Swarm not listening, running in offline mode.")
Expand Down Expand Up @@ -781,10 +780,9 @@ func printSwarmAddrs(node *core.IpfsNode) {
for _, addr := range addrs {
fmt.Printf("Swarm announcing %s\n", addr)
}

}

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

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

// collects options and opens the fuse mountpoint
// collects options and opens the fuse mountpoint.
func mountFuse(req *cmds.Request, cctx *oldcmds.Context) error {
cfg, err := cctx.GetConfig()
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion cmd/ipfs/dnsresolve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ func makeResolver(t *testing.T, n uint8) *madns.Resolver {
backend := &madns.MockResolver{
IP: map[string][]net.IPAddr{
"example.com": results,
}}
},
}

resolver, err := madns.NewResolver(madns.WithDefaultResolver(backend))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/ipfs/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func checkWritable(dir string) error {

if os.IsNotExist(err) {
// dir doesn't exist, check that we can create it
return os.Mkdir(dir, 0775)
return os.Mkdir(dir, 0o775)
}

if os.IsPermission(err) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/ipfs/ipfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var Root = &cmds.Command{
Helptext: commands.Root.Helptext,
}

// commandsClientCmd is the "ipfs commands" command for local cli
// commandsClientCmd is the "ipfs commands" command for local cli.
var commandsClientCmd = commands.CommandsCmd(Root)

// Commands in localCommands should always be run locally (even if daemon is running).
Expand Down
12 changes: 7 additions & 5 deletions cmd/ipfs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ import (
"go.opentelemetry.io/otel/trace"
)

// log is the command logger
var log = logging.Logger("cmd/ipfs")
var tracer trace.Tracer
// log is the command logger.
var (
log = logging.Logger("cmd/ipfs")
tracer trace.Tracer
)

// declared as a var for testing purposes
// declared as a var for testing purposes.
var dnsResolver = madns.DefaultResolver

const (
Expand Down Expand Up @@ -73,7 +75,7 @@ func loadPlugins(repoPath string) (*loader.PluginLoader, error) {
// - if user requests help, print it and exit.
// - run the command invocation
// - output the response
// - if anything fails, print error, maybe with help
// - if anything fails, print error, maybe with help.
func main() {
os.Exit(mainRet())
}
Expand Down
Loading

0 comments on commit f12b372

Please sign in to comment.