extract toStrings method

This commit is contained in:
Brian Tiger Chow 2014-11-06 04:19:00 -08:00 committed by Juan Batiz-Benet
parent 86f0aac88c
commit 4c029a8617

View File

@ -37,17 +37,13 @@ var pinCmd = &cmds.Command{
}
}*/
paths := make([]string, 0)
for _, arg := range req.Arguments() {
path, ok := arg.(string)
if !ok {
res.SetError(errors.New("cast error"), cmds.ErrNormal)
return
}
paths = append(paths, path)
paths, err := toStrings(req.Arguments())
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
_, err := pin(n, paths, recursive)
_, err = pin(n, paths, recursive)
if err != nil {
res.SetError(err, cmds.ErrNormal)
}
@ -126,3 +122,15 @@ func pin(n *core.IpfsNode, paths []string, recursive bool) ([]*merkledag.Node, e
return dagnodes, nil
}
func toStrings(slice []interface{}) ([]string, error) {
strs := make([]string, 0)
for _, maybe := range slice {
str, ok := maybe.(string)
if !ok {
return nil, errors.New("cast error")
}
strs = append(strs, str)
}
return strs, nil
}