本文整理汇总了Golang中github.com/ipfs/go-ipfs/commands.Command.Call方法的典型用法代码示例。如果您正苦于以下问题:Golang Command.Call方法的具体用法?Golang Command.Call怎么用?Golang Command.Call使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/ipfs/go-ipfs/commands.Command
的用法示例。
在下文中一共展示了Command.Call方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: callCommand
func callCommand(ctx context.Context, req cmds.Request, root *cmds.Command, cmd *cmds.Command) (cmds.Response, error) {
log.Info(config.EnvDir, " ", req.InvocContext().ConfigRoot)
var res cmds.Response
err := req.SetRootContext(ctx)
if err != nil {
return nil, err
}
details, err := commandDetails(req.Path(), root)
if err != nil {
return nil, err
}
client, err := commandShouldRunOnDaemon(*details, req, root)
if err != nil {
return nil, err
}
err = callPreCommandHooks(ctx, *details, req, root)
if err != nil {
return nil, err
}
if cmd.PreRun != nil {
err = cmd.PreRun(req)
if err != nil {
return nil, err
}
}
if client != nil && !cmd.External {
log.Debug("Executing command via API")
res, err = client.Send(req)
if err != nil {
if isConnRefused(err) {
err = repo.ErrApiNotRunning
}
return nil, err
}
} else {
log.Debug("Executing command locally")
err := req.SetRootContext(ctx)
if err != nil {
return nil, err
}
// Okay!!!!! NOW we can call the command.
res = root.Call(req)
}
if cmd.PostRun != nil {
cmd.PostRun(req, res)
}
return res, nil
}
示例2: callCommand
func callCommand(ctx context.Context, req cmds.Request, root *cmds.Command, cmd *cmds.Command) (cmds.Response, error) {
log.Info(config.EnvDir, " ", req.InvocContext().ConfigRoot)
var res cmds.Response
err := req.SetRootContext(ctx)
if err != nil {
return nil, err
}
details, err := commandDetails(req.Path(), root)
if err != nil {
return nil, err
}
log.Debug("looking for running daemon...")
useDaemon, err := commandShouldRunOnDaemon(*details, req, root)
if err != nil {
return nil, err
}
err = callPreCommandHooks(ctx, *details, req, root)
if err != nil {
return nil, err
}
if cmd.PreRun != nil {
err = cmd.PreRun(req)
if err != nil {
return nil, err
}
}
if useDaemon {
cfg, err := req.InvocContext().GetConfig()
if err != nil {
return nil, err
}
addr, err := ma.NewMultiaddr(cfg.Addresses.API)
if err != nil {
return nil, err
}
log.Infof("Executing command on daemon running at %s", addr)
_, host, err := manet.DialArgs(addr)
if err != nil {
return nil, err
}
client := cmdsHttp.NewClient(host)
res, err = client.Send(req)
if err != nil {
return nil, err
}
} else {
log.Debug("Executing command locally")
err := req.SetRootContext(ctx)
if err != nil {
return nil, err
}
// Okay!!!!! NOW we can call the command.
res = root.Call(req)
}
if cmd.PostRun != nil {
cmd.PostRun(req, res)
}
return res, nil
}