本文整理汇总了Golang中github.com/docker/docker/api/types/container.RestartPolicy类的典型用法代码示例。如果您正苦于以下问题:Golang RestartPolicy类的具体用法?Golang RestartPolicy怎么用?Golang RestartPolicy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RestartPolicy类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ParseRestartPolicy
// ParseRestartPolicy returns the parsed policy or an error indicating what is incorrect
func ParseRestartPolicy(policy string) (container.RestartPolicy, error) {
p := container.RestartPolicy{}
if policy == "" {
return p, nil
}
parts := strings.Split(policy, ":")
if len(parts) > 2 {
return p, fmt.Errorf("invalid restart policy format")
}
if len(parts) == 2 {
count, err := strconv.Atoi(parts[1])
if err != nil {
return p, fmt.Errorf("maximum retry count must be an integer")
}
p.MaximumRetryCount = count
}
p.Name = parts[0]
return p, nil
}
示例2: ParseRestartPolicy
// ParseRestartPolicy returns the parsed policy or an error indicating what is incorrect
func ParseRestartPolicy(policy string) (container.RestartPolicy, error) {
p := container.RestartPolicy{}
if policy == "" {
return p, nil
}
var (
parts = strings.Split(policy, ":")
name = parts[0]
)
p.Name = name
switch name {
case "always", "unless-stopped":
if len(parts) > 1 {
return p, fmt.Errorf("maximum restart count not valid with restart policy of \"%s\"", name)
}
case "no":
// do nothing
case "on-failure":
if len(parts) > 2 {
return p, fmt.Errorf("restart count format is not valid, usage: 'on-failure:N' or 'on-failure'")
}
if len(parts) == 2 {
count, err := strconv.Atoi(parts[1])
if err != nil {
return p, err
}
p.MaximumRetryCount = count
}
default:
return p, fmt.Errorf("invalid restart policy %s", name)
}
return p, nil
}