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

Added a ResolveFresh function to skip the cache #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean /ipns/[hash] here? Same for the comment above Resolve()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it resolves the thing provided (which may be an ipns or an ipfs thing?) to an ipfs hash

This comment was marked as off-topic.

// 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