mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-22 04:09:04 +08:00
commands: Changed Marshaler to return a io.Reader instead of a []byte
core/commands: Refactored command marshalers
This commit is contained in:
@ -1,8 +1,10 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
cmds "github.com/jbenet/go-ipfs/commands"
|
||||
"github.com/jbenet/go-ipfs/core"
|
||||
@ -33,16 +35,16 @@ var UpdateCmd = &cmds.Command{
|
||||
"log": UpdateLogCmd,
|
||||
},
|
||||
Marshalers: cmds.MarshalerMap{
|
||||
cmds.Text: func(res cmds.Response) ([]byte, error) {
|
||||
cmds.Text: func(res cmds.Response) (io.Reader, error) {
|
||||
v := res.Output().(*UpdateOutput)
|
||||
s := ""
|
||||
var buf bytes.Buffer
|
||||
if v.NewVersion != v.OldVersion {
|
||||
s = fmt.Sprintf("Successfully updated to IPFS version '%s' (from '%s')\n",
|
||||
v.NewVersion, v.OldVersion)
|
||||
buf.WriteString(fmt.Sprintf("Successfully updated to IPFS version '%s' (from '%s')\n",
|
||||
v.NewVersion, v.OldVersion))
|
||||
} else {
|
||||
s = fmt.Sprintf("Already updated to latest version ('%s')\n", v.NewVersion)
|
||||
buf.WriteString(fmt.Sprintf("Already updated to latest version ('%s')\n", v.NewVersion))
|
||||
}
|
||||
return []byte(s), nil
|
||||
return &buf, nil
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -62,16 +64,16 @@ var UpdateCheckCmd = &cmds.Command{
|
||||
},
|
||||
Type: &UpdateOutput{},
|
||||
Marshalers: cmds.MarshalerMap{
|
||||
cmds.Text: func(res cmds.Response) ([]byte, error) {
|
||||
cmds.Text: func(res cmds.Response) (io.Reader, error) {
|
||||
v := res.Output().(*UpdateOutput)
|
||||
s := ""
|
||||
var buf bytes.Buffer
|
||||
if v.NewVersion != v.OldVersion {
|
||||
s = fmt.Sprintf("A new version of IPFS is available ('%s', currently running '%s')\n",
|
||||
v.NewVersion, v.OldVersion)
|
||||
buf.WriteString(fmt.Sprintf("A new version of IPFS is available ('%s', currently running '%s')\n",
|
||||
v.NewVersion, v.OldVersion))
|
||||
} else {
|
||||
s = fmt.Sprintf("Already updated to latest version ('%s')\n", v.NewVersion)
|
||||
buf.WriteString(fmt.Sprintf("Already updated to latest version ('%s')\n", v.NewVersion))
|
||||
}
|
||||
return []byte(s), nil
|
||||
return &buf, nil
|
||||
},
|
||||
},
|
||||
}
|
||||
|
Reference in New Issue
Block a user