agent: use strconv.ParseBool for parsing maintenance enable flag

pull/627/head
Ryan Uber 2015-01-21 09:53:31 -08:00
parent d89af51eb6
commit 9c69dc05fb
1 changed files with 5 additions and 15 deletions

View File

@ -5,6 +5,7 @@ import (
"github.com/hashicorp/consul/consul/structs" "github.com/hashicorp/consul/consul/structs"
"github.com/hashicorp/serf/serf" "github.com/hashicorp/serf/serf"
"net/http" "net/http"
"strconv"
"strings" "strings"
) )
@ -210,20 +211,14 @@ func (s *HTTPServer) AgentServiceMaintenance(resp http.ResponseWriter, req *http
return nil, nil return nil, nil
} }
var enable bool
raw := params.Get("enable") raw := params.Get("enable")
switch raw { enable, err := strconv.ParseBool(raw)
case "true": if err != nil {
enable = true
case "false":
enable = false
default:
resp.WriteHeader(400) resp.WriteHeader(400)
resp.Write([]byte(fmt.Sprintf("Invalid value for enable: %q", raw))) resp.Write([]byte(fmt.Sprintf("Invalid value for enable: %q", raw)))
return nil, nil return nil, nil
} }
var err error
if enable { if enable {
if err = s.agent.EnableServiceMaintenance(serviceID); err != nil { if err = s.agent.EnableServiceMaintenance(serviceID); err != nil {
resp.WriteHeader(404) resp.WriteHeader(404)
@ -253,14 +248,9 @@ func (s *HTTPServer) AgentNodeMaintenance(resp http.ResponseWriter, req *http.Re
return nil, nil return nil, nil
} }
var enable bool
raw := params.Get("enable") raw := params.Get("enable")
switch raw { enable, err := strconv.ParseBool(raw)
case "true": if err != nil {
enable = true
case "false":
enable = false
default:
resp.WriteHeader(400) resp.WriteHeader(400)
resp.Write([]byte(fmt.Sprintf("Invalid value for enable: %q", raw))) resp.Write([]byte(fmt.Sprintf("Invalid value for enable: %q", raw)))
return nil, nil return nil, nil