本文整理汇总了Golang中github.com/hashicorp/nomad/nomad/structs.Service.Checks方法的典型用法代码示例。如果您正苦于以下问题:Golang Service.Checks方法的具体用法?Golang Service.Checks怎么用?Golang Service.Checks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/hashicorp/nomad/nomad/structs.Service
的用法示例。
在下文中一共展示了Service.Checks方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: parseChecks
func parseChecks(service *structs.Service, checkObjs *ast.ObjectList) error {
service.Checks = make([]*structs.ServiceCheck, len(checkObjs.Items))
for idx, co := range checkObjs.Items {
var check structs.ServiceCheck
var cm map[string]interface{}
if err := hcl.DecodeObject(&cm, co.Val); err != nil {
return err
}
dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
DecodeHook: mapstructure.StringToTimeDurationHookFunc(),
WeaklyTypedInput: true,
Result: &check,
})
if err != nil {
return err
}
if err := dec.Decode(cm); err != nil {
return err
}
service.Checks[idx] = &check
}
return nil
}
示例2: TestConsul_AddCheck_To_Service
func TestConsul_AddCheck_To_Service(t *testing.T) {
apiClient := &mockConsulApiClient{}
c := newConsulService()
c.client = apiClient
task := newTask()
var checks []*structs.ServiceCheck
s1 := structs.Service{
Id: "1-example-cache-redis",
Name: "example-cache-redis",
Tags: []string{"global"},
PortLabel: "db",
Checks: checks,
}
task.Services = append(task.Services, &s1)
c.Register(task, "1")
check1 := structs.ServiceCheck{
Name: "alive",
Type: "tcp",
Interval: 10 * time.Second,
Timeout: 5 * time.Second,
}
s1.Checks = append(s1.Checks, &check1)
c.performSync()
if apiClient.checkRegisterCallCount != 1 {
t.Fatalf("Expected number of check registrations: %v, Actual: %v", 1, apiClient.checkRegisterCallCount)
}
}
示例3: parseChecks
func parseChecks(service *structs.Service, checkObjs *ast.ObjectList) error {
service.Checks = make([]*structs.ServiceCheck, len(checkObjs.Items))
for idx, co := range checkObjs.Items {
// Check for invalid keys
valid := []string{
"name",
"type",
"interval",
"timeout",
"path",
"protocol",
"port",
"command",
"args",
"initial_status",
}
if err := checkHCLKeys(co.Val, valid); err != nil {
return multierror.Prefix(err, "check ->")
}
var check structs.ServiceCheck
var cm map[string]interface{}
if err := hcl.DecodeObject(&cm, co.Val); err != nil {
return err
}
dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
DecodeHook: mapstructure.StringToTimeDurationHookFunc(),
WeaklyTypedInput: true,
Result: &check,
})
if err != nil {
return err
}
if err := dec.Decode(cm); err != nil {
return err
}
service.Checks[idx] = &check
}
return nil
}