Skip to content

Commit

Permalink
http 400: rename to readJSONRespondError
Browse files Browse the repository at this point in the history
  • Loading branch information
gregwebs committed Jul 4, 2018
1 parent 1bf9bb4 commit b0e44a6
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions server/api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down Expand Up @@ -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
}

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion server/api/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion server/api/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion server/api/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions server/api/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion server/api/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions server/api/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand All @@ -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()
Expand All @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions table/namespace_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"]
Expand All @@ -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"]
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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"]
Expand Down

0 comments on commit b0e44a6

Please sign in to comment.