From 73a9c1389e41a79df2234bdc558958a508a691a1 Mon Sep 17 00:00:00 2001 From: Tarrant Date: Thu, 24 Apr 2014 19:44:27 -0700 Subject: [PATCH] When mangaling JSON to parse durations do a case insensitive key lookup --- command/agent/agent_endpoint.go | 11 +++++++++-- command/agent/config.go | 23 +++++++++++++++++++---- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/command/agent/agent_endpoint.go b/command/agent/agent_endpoint.go index 6d31d786e..f4b9c06d7 100644 --- a/command/agent/agent_endpoint.go +++ b/command/agent/agent_endpoint.go @@ -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 { diff --git a/command/agent/config.go b/command/agent/config.go index 22789cbdc..7dfd2a945 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -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 } } }