use constants from http package

This commit is contained in:
Tim Gross 2020-06-15 16:00:44 -04:00
parent b93efc16d5
commit 161bcd9479
1 changed files with 29 additions and 29 deletions

View File

@ -8,8 +8,8 @@ import (
) )
func (s *HTTPServer) DeploymentsRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) { func (s *HTTPServer) DeploymentsRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
if req.Method != "GET" { if req.Method != http.MethodGet {
return nil, CodedError(405, ErrInvalidMethod) return nil, CodedError(http.StatusMethodNotAllowed, ErrInvalidMethod)
} }
args := structs.DeploymentListRequest{} args := structs.DeploymentListRequest{}
@ -57,8 +57,8 @@ func (s *HTTPServer) DeploymentSpecificRequest(resp http.ResponseWriter, req *ht
// TODO test and api // TODO test and api
func (s *HTTPServer) deploymentFail(resp http.ResponseWriter, req *http.Request, deploymentID string) (interface{}, error) { func (s *HTTPServer) deploymentFail(resp http.ResponseWriter, req *http.Request, deploymentID string) (interface{}, error) {
if req.Method != "PUT" && req.Method != "POST" { if req.Method != http.MethodPut && req.Method != http.MethodPost {
return nil, CodedError(405, ErrInvalidMethod) return nil, CodedError(http.StatusMethodNotAllowed, ErrInvalidMethod)
} }
args := structs.DeploymentFailRequest{ args := structs.DeploymentFailRequest{
DeploymentID: deploymentID, DeploymentID: deploymentID,
@ -74,19 +74,19 @@ func (s *HTTPServer) deploymentFail(resp http.ResponseWriter, req *http.Request,
} }
func (s *HTTPServer) deploymentPause(resp http.ResponseWriter, req *http.Request, deploymentID string) (interface{}, error) { func (s *HTTPServer) deploymentPause(resp http.ResponseWriter, req *http.Request, deploymentID string) (interface{}, error) {
if req.Method != "PUT" && req.Method != "POST" { if req.Method != http.MethodPut && req.Method != http.MethodPost {
return nil, CodedError(405, ErrInvalidMethod) return nil, CodedError(http.StatusMethodNotAllowed, ErrInvalidMethod)
} }
var pauseRequest structs.DeploymentPauseRequest var pauseRequest structs.DeploymentPauseRequest
if err := decodeBody(req, &pauseRequest); err != nil { if err := decodeBody(req, &pauseRequest); err != nil {
return nil, CodedError(400, err.Error()) return nil, CodedError(http.StatusBadRequest, err.Error())
} }
if pauseRequest.DeploymentID == "" { if pauseRequest.DeploymentID == "" {
return nil, CodedError(400, "DeploymentID must be specified") return nil, CodedError(http.StatusBadRequest, "DeploymentID must be specified")
} }
if pauseRequest.DeploymentID != deploymentID { if pauseRequest.DeploymentID != deploymentID {
return nil, CodedError(400, "Deployment ID does not match") return nil, CodedError(http.StatusBadRequest, "Deployment ID does not match")
} }
s.parseWriteRequest(req, &pauseRequest.WriteRequest) s.parseWriteRequest(req, &pauseRequest.WriteRequest)
@ -99,19 +99,19 @@ func (s *HTTPServer) deploymentPause(resp http.ResponseWriter, req *http.Request
} }
func (s *HTTPServer) deploymentPromote(resp http.ResponseWriter, req *http.Request, deploymentID string) (interface{}, error) { func (s *HTTPServer) deploymentPromote(resp http.ResponseWriter, req *http.Request, deploymentID string) (interface{}, error) {
if req.Method != "PUT" && req.Method != "POST" { if req.Method != http.MethodPut && req.Method != http.MethodPost {
return nil, CodedError(405, ErrInvalidMethod) return nil, CodedError(http.StatusMethodNotAllowed, ErrInvalidMethod)
} }
var promoteRequest structs.DeploymentPromoteRequest var promoteRequest structs.DeploymentPromoteRequest
if err := decodeBody(req, &promoteRequest); err != nil { if err := decodeBody(req, &promoteRequest); err != nil {
return nil, CodedError(400, err.Error()) return nil, CodedError(http.StatusBadRequest, err.Error())
} }
if promoteRequest.DeploymentID == "" { if promoteRequest.DeploymentID == "" {
return nil, CodedError(400, "DeploymentID must be specified") return nil, CodedError(http.StatusBadRequest, "DeploymentID must be specified")
} }
if promoteRequest.DeploymentID != deploymentID { if promoteRequest.DeploymentID != deploymentID {
return nil, CodedError(400, "Deployment ID does not match") return nil, CodedError(http.StatusBadRequest, "Deployment ID does not match")
} }
s.parseWriteRequest(req, &promoteRequest.WriteRequest) s.parseWriteRequest(req, &promoteRequest.WriteRequest)
@ -124,19 +124,19 @@ func (s *HTTPServer) deploymentPromote(resp http.ResponseWriter, req *http.Reque
} }
func (s *HTTPServer) deploymentUnblock(resp http.ResponseWriter, req *http.Request, deploymentID string) (interface{}, error) { func (s *HTTPServer) deploymentUnblock(resp http.ResponseWriter, req *http.Request, deploymentID string) (interface{}, error) {
if req.Method != "PUT" && req.Method != "POST" { if req.Method != http.MethodPut && req.Method != http.MethodPost {
return nil, CodedError(405, ErrInvalidMethod) return nil, CodedError(http.StatusMethodNotAllowed, ErrInvalidMethod)
} }
var unblockRequest structs.DeploymentUnblockRequest var unblockRequest structs.DeploymentUnblockRequest
if err := decodeBody(req, &unblockRequest); err != nil { if err := decodeBody(req, &unblockRequest); err != nil {
return nil, CodedError(400, err.Error()) return nil, CodedError(http.StatusBadRequest, err.Error())
} }
if unblockRequest.DeploymentID == "" { if unblockRequest.DeploymentID == "" {
return nil, CodedError(400, "DeploymentID must be specified") return nil, CodedError(http.StatusBadRequest, "DeploymentID must be specified")
} }
if unblockRequest.DeploymentID != deploymentID { if unblockRequest.DeploymentID != deploymentID {
return nil, CodedError(400, "Deployment ID does not match") return nil, CodedError(http.StatusBadRequest, "Deployment ID does not match")
} }
s.parseWriteRequest(req, &unblockRequest.WriteRequest) s.parseWriteRequest(req, &unblockRequest.WriteRequest)
@ -149,19 +149,19 @@ func (s *HTTPServer) deploymentUnblock(resp http.ResponseWriter, req *http.Reque
} }
func (s *HTTPServer) deploymentSetAllocHealth(resp http.ResponseWriter, req *http.Request, deploymentID string) (interface{}, error) { func (s *HTTPServer) deploymentSetAllocHealth(resp http.ResponseWriter, req *http.Request, deploymentID string) (interface{}, error) {
if req.Method != "PUT" && req.Method != "POST" { if req.Method != http.MethodPut && req.Method != http.MethodPost {
return nil, CodedError(405, ErrInvalidMethod) return nil, CodedError(http.StatusMethodNotAllowed, ErrInvalidMethod)
} }
var healthRequest structs.DeploymentAllocHealthRequest var healthRequest structs.DeploymentAllocHealthRequest
if err := decodeBody(req, &healthRequest); err != nil { if err := decodeBody(req, &healthRequest); err != nil {
return nil, CodedError(400, err.Error()) return nil, CodedError(http.StatusBadRequest, err.Error())
} }
if healthRequest.DeploymentID == "" { if healthRequest.DeploymentID == "" {
return nil, CodedError(400, "DeploymentID must be specified") return nil, CodedError(http.StatusBadRequest, "DeploymentID must be specified")
} }
if healthRequest.DeploymentID != deploymentID { if healthRequest.DeploymentID != deploymentID {
return nil, CodedError(400, "Deployment ID does not match") return nil, CodedError(http.StatusBadRequest, "Deployment ID does not match")
} }
s.parseWriteRequest(req, &healthRequest.WriteRequest) s.parseWriteRequest(req, &healthRequest.WriteRequest)
@ -174,8 +174,8 @@ func (s *HTTPServer) deploymentSetAllocHealth(resp http.ResponseWriter, req *htt
} }
func (s *HTTPServer) deploymentAllocations(resp http.ResponseWriter, req *http.Request, deploymentID string) (interface{}, error) { func (s *HTTPServer) deploymentAllocations(resp http.ResponseWriter, req *http.Request, deploymentID string) (interface{}, error) {
if req.Method != "GET" { if req.Method != http.MethodGet {
return nil, CodedError(405, ErrInvalidMethod) return nil, CodedError(http.StatusMethodNotAllowed, ErrInvalidMethod)
} }
args := structs.DeploymentSpecificRequest{ args := structs.DeploymentSpecificRequest{
@ -201,8 +201,8 @@ func (s *HTTPServer) deploymentAllocations(resp http.ResponseWriter, req *http.R
} }
func (s *HTTPServer) deploymentQuery(resp http.ResponseWriter, req *http.Request, deploymentID string) (interface{}, error) { func (s *HTTPServer) deploymentQuery(resp http.ResponseWriter, req *http.Request, deploymentID string) (interface{}, error) {
if req.Method != "GET" { if req.Method != http.MethodGet {
return nil, CodedError(405, ErrInvalidMethod) return nil, CodedError(http.StatusMethodNotAllowed, ErrInvalidMethod)
} }
args := structs.DeploymentSpecificRequest{ args := structs.DeploymentSpecificRequest{
@ -219,7 +219,7 @@ func (s *HTTPServer) deploymentQuery(resp http.ResponseWriter, req *http.Request
setMeta(resp, &out.QueryMeta) setMeta(resp, &out.QueryMeta)
if out.Deployment == nil { if out.Deployment == nil {
return nil, CodedError(404, "deployment not found") return nil, CodedError(http.StatusNotFound, "deployment not found")
} }
return out.Deployment, nil return out.Deployment, nil
} }