From dc378f9e202bd5e8b7927c750d06d8edffa872f5 Mon Sep 17 00:00:00 2001 From: Wayback Archiver <66856220+waybackarchiver@users.noreply.github.com> Date: Tue, 2 May 2023 06:25:10 +0100 Subject: [PATCH] Refine error return --- pinner.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pinner.go b/pinner.go index c91db01..24939f2 100644 --- a/pinner.go +++ b/pinner.go @@ -12,6 +12,8 @@ import ( "github.com/wabarc/ipfs-pinner/pkg/web3storage" ) +var ErrPinner = fmt.Errorf("unsupported pinner") + const ( Infura = "infura" Pinata = "pinata" @@ -37,12 +39,12 @@ type Config struct { //nolint:gocyclo func (cfg *Config) Pin(path interface{}) (cid string, err error) { // TODO using generics - err = fmt.Errorf("unsupported pinner") + err = ErrPinner switch v := path.(type) { case string: - _, err := os.Lstat(v) + _, err = os.Lstat(v) if err != nil { - return "", err + return } switch cfg.Pinner { case Infura: @@ -99,7 +101,7 @@ func (cfg *Config) Pin(path interface{}) (cid string, err error) { // PinHash pins from any IPFS node, returns the original cid and an error. func (cfg *Config) PinHash(cid string) (string, error) { ok := false - err := fmt.Errorf("unsupported pinner") + err := ErrPinner switch cfg.Pinner { case Infura: inf := &infura.Infura{Apikey: cfg.Apikey, Secret: cfg.Secret, Client: cfg.Client}