本文整理汇总了Golang中github.com/ipfs/go-ipfs/commands.Request.Arguments方法的典型用法代码示例。如果您正苦于以下问题:Golang Request.Arguments方法的具体用法?Golang Request.Arguments怎么用?Golang Request.Arguments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/ipfs/go-ipfs/commands.Request
的用法示例。
在下文中一共展示了Request.Arguments方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getQuery
func getQuery(req cmds.Request) (string, error) {
query := url.Values{}
for k, v := range req.Options() {
if OptionSkipMap[k] {
continue
}
str := fmt.Sprintf("%v", v)
query.Set(k, str)
}
args := req.Arguments()
argDefs := req.Command().Arguments
argDefIndex := 0
for _, arg := range args {
argDef := argDefs[argDefIndex]
// skip ArgFiles
for argDef.Type == cmds.ArgFile {
argDefIndex++
argDef = argDefs[argDefIndex]
}
query.Add("arg", arg)
if len(argDefs) > argDefIndex+1 {
argDefIndex++
}
}
return query.Encode(), nil
}
示例2: tourRunFunc
func tourRunFunc(req cmds.Request, res cmds.Response) {
cfg, err := req.InvocContext().GetConfig()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
id := tour.TopicID(cfg.Tour.Last)
if len(req.Arguments()) > 0 {
id = tour.TopicID(req.Arguments()[0])
}
w := new(bytes.Buffer)
t, err := tourGet(id)
if err != nil {
// If no topic exists for this id, we handle this error right here.
// To help the user achieve the task, we construct a response
// comprised of...
// 1) a simple error message
// 2) the full list of topics
fmt.Fprintln(w, "ERROR")
fmt.Fprintln(w, err)
fmt.Fprintln(w, "")
fprintTourList(w, tour.TopicID(cfg.Tour.Last))
res.SetOutput(w)
return
}
fprintTourShow(w, t)
res.SetOutput(w)
}
示例3: setDataCaller
func setDataCaller(req cmds.Request, root *dag.Node) (key.Key, error) {
if len(req.Arguments()) < 3 {
return "", fmt.Errorf("not enough arguments for set-data")
}
nd, err := req.InvocContext().GetNode()
if err != nil {
return "", err
}
root.Data = []byte(req.Arguments()[2])
newkey, err := nd.DAG.Add(root)
if err != nil {
return "", err
}
return newkey, nil
}
示例4: rmLinkCaller
func rmLinkCaller(req cmds.Request, root *dag.Node) (key.Key, error) {
if len(req.Arguments()) < 3 {
return "", fmt.Errorf("not enough arguments for rm-link")
}
nd, err := req.InvocContext().GetNode()
if err != nil {
return "", err
}
path := req.Arguments()[2]
e := dagutils.NewDagEditor(nd.DAG, root)
err = e.RmLink(req.Context(), path)
if err != nil {
return "", err
}
nnode := e.GetNode()
return nnode.Key()
}
示例5: rmLinkCaller
func rmLinkCaller(req cmds.Request, root *dag.Node) (key.Key, error) {
if len(req.Arguments()) < 3 {
return "", fmt.Errorf("not enough arguments for rm-link")
}
nd, err := req.InvocContext().GetNode()
if err != nil {
return "", err
}
name := req.Arguments()[2]
err = root.RemoveNodeLink(name)
if err != nil {
return "", err
}
newkey, err := nd.DAG.Add(root)
if err != nil {
return "", err
}
return newkey, nil
}
示例6: addLinkCaller
func addLinkCaller(req cmds.Request, root *dag.Node) (key.Key, error) {
if len(req.Arguments()) < 4 {
return "", fmt.Errorf("not enough arguments for add-link")
}
nd, err := req.InvocContext().GetNode()
if err != nil {
return "", err
}
path := req.Arguments()[2]
childk := key.B58KeyDecode(req.Arguments()[3])
create, _, err := req.Option("create").Bool()
if err != nil {
return "", err
}
var createfunc func() *dag.Node
if create {
createfunc = func() *dag.Node {
return &dag.Node{Data: ft.FolderPBData()}
}
}
e := dagutils.NewDagEditor(nd.DAG, root)
childnd, err := nd.DAG.Get(req.Context(), childk)
if err != nil {
return "", err
}
err = e.InsertNodeAtPath(req.Context(), path, childnd, createfunc)
if err != nil {
return "", err
}
nnode := e.GetNode()
return nnode.Key()
}
示例7: addLinkCaller
func addLinkCaller(req cmds.Request, root *dag.Node) (key.Key, error) {
if len(req.Arguments()) < 4 {
return "", fmt.Errorf("not enough arguments for add-link")
}
nd, err := req.InvocContext().GetNode()
if err != nil {
return "", err
}
path := req.Arguments()[2]
childk := key.B58KeyDecode(req.Arguments()[3])
parts := strings.Split(path, "/")
nnode, err := insertNodeAtPath(req.Context(), nd.DAG, root, parts, childk)
if err != nil {
return "", err
}
return nnode.Key()
}