github.com/zignig/go-ipfs@v0.0.0-20141111235910-c9e5fdf55a52/core/commands2/resolve.go (about) 1 package commands 2 3 import ( 4 "errors" 5 6 cmds "github.com/jbenet/go-ipfs/commands" 7 ) 8 9 var resolveCmd = &cmds.Command{ 10 Description: "Gets the value currently published at an IPNS name", 11 Help: `IPNS is a PKI namespace, where names are the hashes of public keys, and 12 the private key enables publishing new (signed) values. In resolve, the 13 default value of <name> is your own identity public key. 14 15 16 Examples: 17 18 Resolve the value of your identity: 19 20 > ipfs name resolve 21 QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy 22 23 Resolve te value of another name: 24 25 > ipfs name resolve QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n 26 QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy 27 28 `, 29 30 Arguments: []cmds.Argument{ 31 cmds.StringArg("name", false, false, "The IPNS name to resolve. Defaults to your node's peerID."), 32 }, 33 Run: func(req cmds.Request) (interface{}, error) { 34 35 n := req.Context().Node 36 var name string 37 38 if n.Network == nil { 39 return nil, errNotOnline 40 } 41 42 if len(req.Arguments()) == 0 { 43 if n.Identity == nil { 44 return nil, errors.New("Identity not loaded!") 45 } 46 name = n.Identity.ID().String() 47 48 } else { 49 var ok bool 50 name, ok = req.Arguments()[0].(string) 51 if !ok { 52 return nil, errors.New("cast error") 53 } 54 } 55 56 output, err := n.Namesys.Resolve(name) 57 if err != nil { 58 return nil, err 59 } 60 61 return output, nil 62 }, 63 Marshallers: map[cmds.EncodingType]cmds.Marshaller{ 64 cmds.Text: func(res cmds.Response) ([]byte, error) { 65 output := res.Output().(string) 66 return []byte(output), nil 67 }, 68 }, 69 }