1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-08-24 02:20:52 +08:00

style: gofumpt and godot [skip changelog] (#10081)

This commit is contained in:
Kay
2023-08-17 15:32:08 +03:30
committed by GitHub
parent b4f415088f
commit f12b372af9
148 changed files with 449 additions and 433 deletions

View File

@ -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 == "" {
@ -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 {
@ -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 {
@ -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{
@ -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 {

View File

@ -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
@ -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
@ -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
}
@ -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{}
)

View File

@ -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 {

View File

@ -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))
@ -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 {

View File

@ -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) {
@ -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
}

View File

@ -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 {

View File

@ -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" {

View File

@ -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 {

View File

@ -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
}
@ -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

View File

@ -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()
@ -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
@ -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)

View File

@ -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
}