forked from 42cc/go-ipfs-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipns.go
45 lines (36 loc) · 793 Bytes
/
ipns.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package shell
import (
"encoding/json"
)
// Publish updates a mutable name to point to a given value
func (s *Shell) Publish(node string, value string) error {
args := []string{value}
if node != "" {
args = []string{node, value}
}
resp, err := s.newRequest("name/publish", args...).Send(s.httpcli)
if err != nil {
return err
}
defer resp.Close()
if resp.Error != nil {
return resp.Error
}
return nil
}
func (s *Shell) Resolve(id string) (string, error) {
resp, err := s.newRequest("name/resolve", id).Send(s.httpcli)
if err != nil {
return "", err
}
defer resp.Close()
if resp.Error != nil {
return "", resp.Error
}
var out struct{ Path string }
err = json.NewDecoder(resp.Output).Decode(&out)
if err != nil {
return "", err
}
return out.Path, nil
}