From b0e44a6bb1495e8f71b2513082ec6e3aa957d83c Mon Sep 17 00:00:00 2001 From: Greg Weber Date: Mon, 2 Jul 2018 07:35:32 -0500 Subject: [PATCH] http 400: rename to readJSONRespondError --- server/api/config.go | 8 ++++---- server/api/member.go | 2 +- server/api/operator.go | 2 +- server/api/scheduler.go | 2 +- server/api/store.go | 4 ++-- server/api/util.go | 2 +- server/api/util_test.go | 6 +++--- table/namespace_handler.go | 10 +++++----- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/server/api/config.go b/server/api/config.go index 7b962a91ef6..f81a7920d0c 100644 --- a/server/api/config.go +++ b/server/api/config.go @@ -74,7 +74,7 @@ func (h *confHandler) GetSchedule(w http.ResponseWriter, r *http.Request) { func (h *confHandler) SetSchedule(w http.ResponseWriter, r *http.Request) { config := h.svr.GetScheduleConfig() - if err := jsonRespondError(h.rd, w, r.Body, &config); err != nil { + if err := readJSONRespondError(h.rd, w, r.Body, &config); err != nil { return } @@ -91,7 +91,7 @@ func (h *confHandler) GetReplication(w http.ResponseWriter, r *http.Request) { func (h *confHandler) SetReplication(w http.ResponseWriter, r *http.Request) { config := h.svr.GetReplicationConfig() - if err := jsonRespondError(h.rd, w, r.Body, &config); err != nil { + if err := readJSONRespondError(h.rd, w, r.Body, &config); err != nil { return } @@ -123,7 +123,7 @@ func (h *confHandler) SetNamespace(w http.ResponseWriter, r *http.Request) { } config := h.svr.GetNamespaceConfig(name) - if err := jsonRespondError(h.rd, w, r.Body, &config); err != nil { + if err := readJSONRespondError(h.rd, w, r.Body, &config); err != nil { return } @@ -150,7 +150,7 @@ func (h *confHandler) GetLabelProperty(w http.ResponseWriter, r *http.Request) { func (h *confHandler) SetLabelProperty(w http.ResponseWriter, r *http.Request) { input := make(map[string]string) - if err := jsonRespondError(h.rd, w, r.Body, &input); err != nil { + if err := readJSONRespondError(h.rd, w, r.Body, &input); err != nil { return } var err error diff --git a/server/api/member.go b/server/api/member.go index 24d09f909f8..6fa331b6c47 100644 --- a/server/api/member.go +++ b/server/api/member.go @@ -137,7 +137,7 @@ func (h *memberHandler) SetMemberPropertyByName(w http.ResponseWriter, r *http.R } var input map[string]interface{} - if err := jsonRespondError(h.rd, w, r.Body, &input); err != nil { + if err := readJSONRespondError(h.rd, w, r.Body, &input); err != nil { return } for k, v := range input { diff --git a/server/api/operator.go b/server/api/operator.go index 7dbcaf41b1b..72daa91b812 100644 --- a/server/api/operator.go +++ b/server/api/operator.go @@ -90,7 +90,7 @@ func (h *operatorHandler) List(w http.ResponseWriter, r *http.Request) { func (h *operatorHandler) Post(w http.ResponseWriter, r *http.Request) { var input map[string]interface{} - if err := jsonRespondError(h.r, w, r.Body, &input); err != nil { + if err := readJSONRespondError(h.r, w, r.Body, &input); err != nil { return } diff --git a/server/api/scheduler.go b/server/api/scheduler.go index 97967266158..f7e77dcf385 100644 --- a/server/api/scheduler.go +++ b/server/api/scheduler.go @@ -44,7 +44,7 @@ func (h *schedulerHandler) List(w http.ResponseWriter, r *http.Request) { func (h *schedulerHandler) Post(w http.ResponseWriter, r *http.Request) { var input map[string]interface{} - if err := jsonRespondError(h.r, w, r.Body, &input); err != nil { + if err := readJSONRespondError(h.r, w, r.Body, &input); err != nil { return } diff --git a/server/api/store.go b/server/api/store.go index 893e68453d2..6f19d3ee382 100644 --- a/server/api/store.go +++ b/server/api/store.go @@ -232,7 +232,7 @@ func (h *storeHandler) SetLabels(w http.ResponseWriter, r *http.Request) { } var input map[string]string - if err := jsonRespondError(h.rd, w, r.Body, &input); err != nil { + if err := readJSONRespondError(h.rd, w, r.Body, &input); err != nil { return } @@ -268,7 +268,7 @@ func (h *storeHandler) SetWeight(w http.ResponseWriter, r *http.Request) { } var input map[string]interface{} - if err := jsonRespondError(h.rd, w, r.Body, &input); err != nil { + if err := readJSONRespondError(h.rd, w, r.Body, &input); err != nil { return } diff --git a/server/api/util.go b/server/api/util.go index 7f9cdaca246..ac081107a45 100644 --- a/server/api/util.go +++ b/server/api/util.go @@ -26,7 +26,7 @@ import ( "github.com/unrolled/render" ) -func jsonRespondError(r *render.Render, w http.ResponseWriter, body io.ReadCloser, data interface{}) error { +func readJSONRespondError(r *render.Render, w http.ResponseWriter, body io.ReadCloser, data interface{}) error { err := apiutil.ReadJSON(body, data) if err == nil { return nil diff --git a/server/api/util_test.go b/server/api/util_test.go index 869e1e56258..1a5dde4a4d6 100644 --- a/server/api/util_test.go +++ b/server/api/util_test.go @@ -34,7 +34,7 @@ func (s *testUtilSuite) TestJsonRespondErrorOk(c *C) { body := ioutil.NopCloser(bytes.NewBufferString("{\"zone\":\"cn\", \"host\":\"local\"}")) var input map[string]string output := map[string]string{"zone": "cn", "host": "local"} - err := jsonRespondError(rd, response, body, &input) + err := readJSONRespondError(rd, response, body, &input) c.Assert(err, IsNil) c.Assert(input["zone"], Equals, output["zone"]) c.Assert(input["host"], Equals, output["host"]) @@ -49,7 +49,7 @@ func (s *testUtilSuite) TestJsonRespondErrorBadInput(c *C) { response := httptest.NewRecorder() body := ioutil.NopCloser(bytes.NewBufferString("{\"zone\":\"cn\", \"host\":\"local\"}")) var input []string - err := jsonRespondError(rd, response, body, &input) + err := readJSONRespondError(rd, response, body, &input) c.Assert(err, NotNil) c.Assert(err.Error(), Equals, "json: cannot unmarshal object into Go value of type []string") result := response.Result() @@ -58,7 +58,7 @@ func (s *testUtilSuite) TestJsonRespondErrorBadInput(c *C) { { body := ioutil.NopCloser(bytes.NewBufferString("{\"zone\":\"cn\",")) var input []string - err := jsonRespondError(rd, response, body, &input) + err := readJSONRespondError(rd, response, body, &input) c.Assert(err, NotNil) c.Assert(err.Error(), Equals, "unexpected end of JSON input") result := response.Result() diff --git a/table/namespace_handler.go b/table/namespace_handler.go index c99a429a89f..e924fb9ddf8 100644 --- a/table/namespace_handler.go +++ b/table/namespace_handler.go @@ -57,7 +57,7 @@ func (h *tableNamespaceHandler) Get(w http.ResponseWriter, r *http.Request) { h.rd.JSON(w, http.StatusOK, nsInfo) } -func jsonRespondError(r *render.Render, w http.ResponseWriter, body io.ReadCloser, data interface{}) (err error) { +func readJSONRespondError(r *render.Render, w http.ResponseWriter, body io.ReadCloser, data interface{}) (err error) { if err = apiutil.ReadJSON(body, &data); err != nil { switch err.(type) { case apiutil.JSONError: @@ -73,7 +73,7 @@ func jsonRespondError(r *render.Render, w http.ResponseWriter, body io.ReadClose // Post creates a namespace. func (h *tableNamespaceHandler) Post(w http.ResponseWriter, r *http.Request) { var input map[string]string - if err := jsonRespondError(h.rd, w, r.Body, &input); err != nil { + if err := readJSONRespondError(h.rd, w, r.Body, &input); err != nil { return } ns := input["namespace"] @@ -89,7 +89,7 @@ func (h *tableNamespaceHandler) Post(w http.ResponseWriter, r *http.Request) { func (h *tableNamespaceHandler) Update(w http.ResponseWriter, r *http.Request) { var input map[string]string - if err := jsonRespondError(h.rd, w, r.Body, &input); err != nil { + if err := readJSONRespondError(h.rd, w, r.Body, &input); err != nil { return } tableIDStr := input["table_id"] @@ -128,7 +128,7 @@ func (h *tableNamespaceHandler) Update(w http.ResponseWriter, r *http.Request) { func (h *tableNamespaceHandler) SetMetaNamespace(w http.ResponseWriter, r *http.Request) { var input map[string]string - if err := jsonRespondError(h.rd, w, r.Body, &input); err != nil { + if err := readJSONRespondError(h.rd, w, r.Body, &input); err != nil { return } ns := input["namespace"] @@ -160,7 +160,7 @@ func (h *tableNamespaceHandler) SetNamespace(w http.ResponseWriter, r *http.Requ } var input map[string]string - if err := jsonRespondError(h.rd, w, r.Body, &input); err != nil { + if err := readJSONRespondError(h.rd, w, r.Body, &input); err != nil { return } ns := input["namespace"]