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

Commit

Permalink
Added a ResolveFresh function to skip the cache
Browse files Browse the repository at this point in the history
  • Loading branch information
apiarian committed Dec 11, 2016
1 parent 0ee8672 commit 8740b27
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions ipns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 8740b27

Please sign in to comment.