This is an automated email from the ASF dual-hosted git repository. juzhiyuan pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/apisix-dashboard.git
The following commit(s) were added to refs/heads/master by this push: new 537b4ff fix: null value instead of empty slice during JSON marshalling for GET labels (#1741) 537b4ff is described below commit 537b4ffdd5898879cbc611809e503f5e2b943254 Author: Bisakh Mondal <bisakhmonda...@gmail.com> AuthorDate: Tue Apr 13 08:58:55 2021 +0530 fix: null value instead of empty slice during JSON marshalling for GET labels (#1741) --- api/internal/core/store/store.go | 5 +++++ api/internal/handler/label/label.go | 2 +- api/test/e2e/label_test.go | 10 ++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/api/internal/core/store/store.go b/api/internal/core/store/store.go index 9f13f62..d529dd5 100644 --- a/api/internal/core/store/store.go +++ b/api/internal/core/store/store.go @@ -163,6 +163,11 @@ type ListOutput struct { TotalSize int `json:"total_size"` } +// NewListOutput returns JSON marshalling safe struct pointer for empty slice +func NewListOutput() *ListOutput { + return &ListOutput{Rows: make([]interface{}, 0)} +} + var defLessFunc = func(i, j interface{}) bool { iBase := i.(entity.BaseInfoGetter).GetBaseInfo() jBase := j.(entity.BaseInfoGetter).GetBaseInfo() diff --git a/api/internal/handler/label/label.go b/api/internal/handler/label/label.go index 791b034..fc76725 100644 --- a/api/internal/handler/label/label.go +++ b/api/internal/handler/label/label.go @@ -197,7 +197,7 @@ func (h *Handler) List(c droplet.Context) (interface{}, error) { return subsetOf(reqLabels, ls) } - var totalRet = new(store.ListOutput) + var totalRet = store.NewListOutput() var existMap = make(map[string]struct{}) for _, item := range items { ret, err := item.(store.Interface).List(c.Context(), diff --git a/api/test/e2e/label_test.go b/api/test/e2e/label_test.go index 3b69577..ab43777 100644 --- a/api/test/e2e/label_test.go +++ b/api/test/e2e/label_test.go @@ -373,6 +373,16 @@ func TestLabel(t *testing.T) { Headers: map[string]string{"Authorization": token}, ExpectStatus: http.StatusOK, }, + { + Desc: "get route label(check empty response)", + Object: ManagerApiExpect(t), + Method: http.MethodGet, + Headers: map[string]string{"Authorization": token}, + Path: "/apisix/admin/labels/route", + ExpectStatus: http.StatusOK, + ExpectBody: "{\"rows\":[],\"total_size\":0}", + Sleep: sleepTime, + }, } for _, tc := range tests {