Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 8740b27

Browse files
committed
Added a ResolveFresh function to skip the cache
1 parent 0ee8672 commit 8740b27

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

ipns.go

+22-5
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,33 @@ func (s *Shell) Publish(node string, value string) error {
2424
return nil
2525
}
2626

27-
// Resolve gets resolves the string provided to an /ipfs/[hash]. If asked to
27+
// Resolve resolves the string provided to an /ipfs/[hash]. If asked to
2828
// resolve an empty string, resolve instead resolves the node's own /ipns value.
2929
func (s *Shell) Resolve(id string) (string, error) {
30-
var resp *Response
31-
var err error
30+
return s.resolve(id, false)
31+
}
32+
33+
// ResolveFresh resolves the string provided to an /ipfs/[hash] without looking
34+
// at the cache. If asked to resolve an empty string, ResolveFresh instead
35+
// resolves the node's own /ipns value.
36+
func (s *Shell) ResolveFresh(id string) (string, error) {
37+
return s.resolve(id, true)
38+
}
39+
40+
func (s *Shell) resolve(id string, nocache bool) (string, error) {
41+
var req *Request
3242
if id != "" {
33-
resp, err = s.newRequest("name/resolve", id).Send(s.httpcli)
43+
req = s.newRequest("name/resolve", id)
3444
} else {
35-
resp, err = s.newRequest("name/resolve").Send(s.httpcli)
45+
req = s.newRequest("name/resolve")
3646
}
47+
48+
if nocache {
49+
req.Opts["nocache"] = "true"
50+
}
51+
// false is the default
52+
53+
resp, err := req.Send(s.httpcli)
3754
if err != nil {
3855
return "", err
3956
}

0 commit comments

Comments
 (0)