本文整理汇总了Golang中github.com/gocircuit/circuit/client.Anchor.Walk方法的典型用法代码示例。如果您正苦于以下问题:Golang Anchor.Walk方法的具体用法?Golang Anchor.Walk怎么用?Golang Anchor.Walk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/gocircuit/circuit/client.Anchor
的用法示例。
在下文中一共展示了Anchor.Walk方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: startNodejs
func startNodejs(host client.Anchor, mysqlIP, mysqlPort string) (ip, port string) {
defer func() {
if recover() != nil {
fatalf("connection to host lost")
}
}()
// Start node.js application
ip = getUbuntuHostPublicIP(host)
port = "8080"
job := host.Walk([]string{"nodejs"})
shell := fmt.Sprintf(
"sudo /usr/bin/nodejs index.js "+
"--mysql_host %s --mysql_port %s --api_host %s --api_port %s "+
"&> /tmp/tutorial-nodejs.log",
mysqlIP, mysqlPort,
"0.0.0.0", port,
)
proc, err := job.MakeProc(client.Cmd{
Path: "/bin/sh",
Dir: "/home/ubuntu/nodejs",
Args: []string{"-c", shell},
Scrub: true,
})
if err != nil {
fatalf("nodejs app already running")
}
proc.Stdin().Close()
proc.Stdout().Close()
proc.Stderr().Close()
return
}
示例2: runShellStdin
func runShellStdin(host client.Anchor, cmd, stdin string) (string, error) {
defer func() {
if recover() != nil {
fatalf("connection to host lost")
}
}()
job := host.Walk([]string{"shelljob", strconv.Itoa(rand.Int())})
proc, _ := job.MakeProc(client.Cmd{
Path: "/bin/sh",
Dir: "/tmp",
Args: []string{"-c", cmd},
Scrub: true,
})
go func() {
io.Copy(proc.Stdin(), bytes.NewBufferString(stdin))
proc.Stdin().Close() // Must close the standard input of the shell process.
}()
proc.Stderr().Close() // Close to indicate discarding standard error
var buf bytes.Buffer
io.Copy(&buf, proc.Stdout())
stat, _ := proc.Wait()
return buf.String(), stat.Exit
}