本文整理汇总了Golang中github.com/Masterminds/cookoo.Params.RequiresValue方法的典型用法代码示例。如果您正苦于以下问题:Golang Params.RequiresValue方法的具体用法?Golang Params.RequiresValue怎么用?Golang Params.RequiresValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/Masterminds/cookoo.Params
的用法示例。
在下文中一共展示了Params.RequiresValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: WaitForStart
// WaitForStart delays until Docker appears to be up and running.
//
// Params:
// - client (*docker.Client): Docker client.
// - timeout (time.Duration): Time after which to give up.
//
// Returns:
// - boolean true if the server is up.
func WaitForStart(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
if ok, missing := p.RequiresValue("client"); !ok {
return nil, &cookoo.FatalError{"Missing required fields: " + strings.Join(missing, ", ")}
}
cli := p.Get("client", nil).(*docli.Client)
timeout := p.Get("timeout", 30*time.Second).(time.Duration)
keepon := true
timer := time.AfterFunc(timeout, func() {
keepon = false
})
for keepon == true {
if err := cli.Ping(); err == nil {
timer.Stop()
log.Infof(c, "Docker is running.")
return true, nil
}
time.Sleep(time.Second)
}
return false, fmt.Errorf("Docker timed out after waiting %s for server.", timeout)
}
示例2: Wait
// Wait waits for a sync.WaitGroup to finish.
//
// Params:
// - wg (Waiter): The thing to wait for.
// - msg (string): The message to print when done. If this is empty, nothing is sent.
// - waiting (string): String to tell what we're waiting for. If empty, nothing is displayed.
// - failures (int): The number of failures that occurred while waiting.
//
// Returns:
// Nothing.
func Wait(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
ok, missing := p.RequiresValue("wg")
if !ok {
return nil, &cookoo.FatalError{"Missing required fields: " + strings.Join(missing, ", ")}
}
wg := p.Get("wg", nil).(Waiter)
msg := p.Get("msg", "").(string)
fails := p.Get("failures", 0).(int)
waitmsg := p.Get("waiting", "").(string)
if len(waitmsg) > 0 {
log.Info(c, waitmsg)
}
wg.Wait()
if len(msg) > 0 {
log.Info(c, msg)
}
if fails > 0 {
return nil, fmt.Errorf("There were %d failures while waiting.", fails)
}
return nil, nil
}