Merge pull request #78 from tarrant/case_insensitive_durations
agent: Case insensitive durations
This commit is contained in:
commit
059d90f81c
|
@ -118,10 +118,17 @@ func (s *HTTPServer) AgentRegisterService(resp http.ResponseWriter, req *http.Re
|
|||
if !ok {
|
||||
return nil
|
||||
}
|
||||
check, ok := rawMap["check"]
|
||||
if !ok {
|
||||
|
||||
var check interface{}
|
||||
for k, v := range rawMap {
|
||||
if strings.ToLower(k) == "check" {
|
||||
check = v
|
||||
}
|
||||
}
|
||||
if check == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return FixupCheckType(check)
|
||||
}
|
||||
if err := decodeBody(req, &args, decodeCB); err != nil {
|
||||
|
|
|
@ -265,23 +265,38 @@ func FixupCheckType(raw interface{}) error {
|
|||
if !ok {
|
||||
return nil
|
||||
}
|
||||
if ttl, ok := rawMap["ttl"]; ok {
|
||||
|
||||
var ttlKey string
|
||||
for k, _ := range rawMap {
|
||||
if strings.ToLower(k) == "ttl" {
|
||||
ttlKey = k
|
||||
}
|
||||
}
|
||||
var intervalKey string
|
||||
for k, _ := range rawMap {
|
||||
if strings.ToLower(k) == "interval" {
|
||||
intervalKey = k
|
||||
}
|
||||
}
|
||||
|
||||
if ttl, ok := rawMap[ttlKey]; ok {
|
||||
ttlS, ok := ttl.(string)
|
||||
if ok {
|
||||
if dur, err := time.ParseDuration(ttlS); err != nil {
|
||||
return err
|
||||
} else {
|
||||
rawMap["ttl"] = dur
|
||||
rawMap[ttlKey] = dur
|
||||
}
|
||||
}
|
||||
}
|
||||
if interval, ok := rawMap["interval"]; ok {
|
||||
|
||||
if interval, ok := rawMap[intervalKey]; ok {
|
||||
intervalS, ok := interval.(string)
|
||||
if ok {
|
||||
if dur, err := time.ParseDuration(intervalS); err != nil {
|
||||
return err
|
||||
} else {
|
||||
rawMap["interval"] = dur
|
||||
rawMap[intervalKey] = dur
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue