From 8740b2764dbaa0b783c2825510f07b783ce4119e Mon Sep 17 00:00:00 2001 From: Aleksandr Pasechnik Date: Sun, 31 Jul 2016 12:46:07 -0400 Subject: [PATCH] Added a ResolveFresh function to skip the cache --- ipns.go | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/ipns.go b/ipns.go index c447e9d40..ebfde5620 100644 --- a/ipns.go +++ b/ipns.go @@ -24,16 +24,33 @@ func (s *Shell) Publish(node string, value string) error { return nil } -// Resolve gets resolves the string provided to an /ipfs/[hash]. If asked to +// Resolve resolves the string provided to an /ipfs/[hash]. If asked to // resolve an empty string, resolve instead resolves the node's own /ipns value. func (s *Shell) Resolve(id string) (string, error) { - var resp *Response - var err error + return s.resolve(id, false) +} + +// ResolveFresh resolves the string provided to an /ipfs/[hash] without looking +// at the cache. If asked to resolve an empty string, ResolveFresh instead +// resolves the node's own /ipns value. +func (s *Shell) ResolveFresh(id string) (string, error) { + return s.resolve(id, true) +} + +func (s *Shell) resolve(id string, nocache bool) (string, error) { + var req *Request if id != "" { - resp, err = s.newRequest("name/resolve", id).Send(s.httpcli) + req = s.newRequest("name/resolve", id) } else { - resp, err = s.newRequest("name/resolve").Send(s.httpcli) + req = s.newRequest("name/resolve") } + + if nocache { + req.Opts["nocache"] = "true" + } + // false is the default + + resp, err := req.Send(s.httpcli) if err != nil { return "", err }