1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-05-20 16:36:46 +08:00

Use variadic options

License: MIT
Signed-off-by: Dirk McCormick <dirkmdev@gmail.com>
This commit is contained in:
Dirk McCormick
2018-02-28 16:57:24 -05:00
parent 5096025df2
commit e8f79c8803
23 changed files with 172 additions and 131 deletions

View File

@ -9,6 +9,7 @@ import (
"github.com/ipfs/go-ipfs/core"
e "github.com/ipfs/go-ipfs/core/commands/e"
ns "github.com/ipfs/go-ipfs/namesys"
nsopts "github.com/ipfs/go-ipfs/namesys/opts"
path "github.com/ipfs/go-ipfs/path"
"gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit"
@ -89,15 +90,14 @@ Resolve the value of an IPFS DAG path:
if strings.HasPrefix(name, "/ipns/") && !recursive {
rc, rcok, _ := req.Option("dht-record-count").Int()
dhtt, dhttok, _ := req.Option("dht-timeout").Int()
opts := ns.DefaultResolveOpts()
opts.Depth = 1
ropts := []nsopts.ResolveOpt{nsopts.Depth(1)}
if rcok {
opts.DhtRecordCount = uint(rc)
ropts = append(ropts, nsopts.DhtRecordCount(uint(rc)))
}
if dhttok {
opts.DhtTimeout = time.Duration(dhtt) * time.Second
ropts = append(ropts, nsopts.DhtTimeout(time.Duration(dhtt)*time.Second))
}
p, err := n.Namesys.Resolve(req.Context(), name, opts)
p, err := n.Namesys.Resolve(req.Context(), name, ropts...)
// ErrResolveRecursion is fine
if err != nil && err != ns.ErrResolveRecursion {
res.SetError(err, cmdkit.ErrNormal)