You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/12/18 12:06:21 UTC

[GitHub] [apisix-dashboard] starsz opened a new pull request #1072: feat: support labels list

starsz opened a new pull request #1072:
URL: https://github.com/apache/apisix-dashboard/pull/1072


   Please answer these questions before submitting a pull request
   
   - Why submit this pull request?
   - [ ] Bugfix
   - [x] New feature provided
   - [ ] Improve performance
   
   - Related issues
   fix #861 
   ___
   ### New feature or improvement
   - Describe the details and related test reports.
   
   Support labels list.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] starsz commented on a change in pull request #1072: feat: support labels list

Posted by GitBox <gi...@apache.org>.
starsz commented on a change in pull request #1072:
URL: https://github.com/apache/apisix-dashboard/pull/1072#discussion_r546478685



##########
File path: api/internal/handler/label/label.go
##########
@@ -0,0 +1,260 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package label
+
+import (
+	"encoding/json"
+	"fmt"
+	"github.com/shiningrush/droplet/data"
+	"net/http"
+	"reflect"
+	"sort"
+	"strings"
+
+	"github.com/gin-gonic/gin"
+	"github.com/shiningrush/droplet"
+	"github.com/shiningrush/droplet/wrapper"
+	wgin "github.com/shiningrush/droplet/wrapper/gin"
+
+	"github.com/apisix/manager-api/internal/core/entity"
+	"github.com/apisix/manager-api/internal/core/store"
+	"github.com/apisix/manager-api/internal/handler"
+	"github.com/apisix/manager-api/internal/utils"
+)
+
+type Handler struct {
+	routeStore    store.Interface
+	serviceStore  store.Interface
+	upstreamStore store.Interface
+	sslStore      store.Interface
+	consumerStore store.Interface
+}
+
+var _ json.Marshaler = Pair{}
+
+type Pair struct {
+	Key string
+	Val string
+}
+
+func (p Pair) MarshalJSON() ([]byte, error) {
+	res := fmt.Sprintf("{\"%s\":\"%s\"}", p.Key, p.Val)

Review comment:
       fixed.And add some tests.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] starsz commented on a change in pull request #1072: feat: support labels list

Posted by GitBox <gi...@apache.org>.
starsz commented on a change in pull request #1072:
URL: https://github.com/apache/apisix-dashboard/pull/1072#discussion_r546468944



##########
File path: api/test/e2e/label_test.go
##########
@@ -0,0 +1,229 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package e2e
+
+import (
+	"net/http"
+	"testing"
+)
+
+func TestLabel(t *testing.T) {
+	// Todo: test ssl after ssl bug fixed
+	tests := []HttpTestCase{
+		{
+			caseDesc: "config route",
+			Object:   ManagerApiExpect(t),
+			Path:     "/apisix/admin/routes/r1",
+			Method:   http.MethodPut,
+			Body: `{
+					"uri": "/hello",
+					"labels": {
+						"build":"16",
+						"env":"production",
+						"version":"v2"
+					},
+					"upstream": {
+						"type": "roundrobin",
+						"nodes": [{
+							"host": "172.16.238.20",
+							"port": 1980,
+							"weight": 1
+						}]
+					}
+				}`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc: "create consumer",
+			Object:   ManagerApiExpect(t),
+			Path:     "/apisix/admin/consumers/c1",
+			Method:   http.MethodPut,
+			Body: `{
+				"username": "jack",
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+				"labels": {
+					"build":"16",
+					"env":"production",
+					"version":"v3"
+				},
+				"desc": "test description"
+			}`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc: "create upstream",
+			Object:   ManagerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/upstreams/u1",
+			Body: `{
+				"nodes": [{
+					"host": "172.16.238.20",
+					"port": 1980,
+					"weight": 1
+				}],
+				"labels": {
+					"build":"17",
+					"env":"production",
+					"version":"v2"
+				},
+				"type": "roundrobin"
+			}`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc: "create service",
+			Object:   ManagerApiExpect(t),
+			Method:   http.MethodPost,
+			Path:     "/apisix/admin/services",
+			Body: `{
+				"id": "s1",
+				"plugins": {
+					"limit-count": {
+						"count": 2,
+						"time_window": 60,
+						"rejected_code": 503,
+						"key": "remote_addr"
+					}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": [{
+						"host": "39.97.63.215",
+						"port": 80,
+						"weight": 1
+					}]
+				},
+				"labels": {
+					"build":"16",
+					"env":"production",
+					"version":"v2",
+					"extra": "test"
+				}
+			}`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "get route label",
+			Object:       ManagerApiExpect(t),
+			Method:       http.MethodGet,
+			Headers:      map[string]string{"Authorization": token},
+			Path:         "/api/labels/route",
+			ExpectStatus: http.StatusOK,
+			ExpectBody:   "{\"build\":\"16\"},{\"env\":\"production\"},{\"version\":\"v2\"}",
+		},
+		{
+			caseDesc:     "get consumer label",
+			Object:       ManagerApiExpect(t),
+			Method:       http.MethodGet,
+			Headers:      map[string]string{"Authorization": token},
+			Path:         "/api/labels/consumer",
+			ExpectStatus: http.StatusOK,
+			ExpectBody:   "{\"build\":\"16\"},{\"env\":\"production\"},{\"version\":\"v3\"}",
+		},
+		{
+			caseDesc:     "get upstream label",
+			Object:       ManagerApiExpect(t),
+			Method:       http.MethodGet,
+			Headers:      map[string]string{"Authorization": token},
+			Path:         "/api/labels/upstream",
+			ExpectStatus: http.StatusOK,
+			ExpectBody:   "{\"build\":\"17\"},{\"env\":\"production\"},{\"version\":\"v2\"}",
+		},
+		{
+			caseDesc:     "get service label",
+			Object:       ManagerApiExpect(t),
+			Method:       http.MethodGet,
+			Headers:      map[string]string{"Authorization": token},
+			Path:         "/api/labels/service",
+			ExpectStatus: http.StatusOK,
+			ExpectBody:   "{\"build\":\"16\"},{\"env\":\"production\"},{\"extra\":\"test\"},{\"version\":\"v2\"}",
+		},
+		{
+			caseDesc:     "get all label",

Review comment:
       Added.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] codecov-io commented on pull request #1072: feat: support labels list

Posted by GitBox <gi...@apache.org>.
codecov-io commented on pull request #1072:
URL: https://github.com/apache/apisix-dashboard/pull/1072#issuecomment-748052557


   # [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1072?src=pr&el=h1) Report
   > Merging [#1072](https://codecov.io/gh/apache/apisix-dashboard/pull/1072?src=pr&el=desc) (1aac174) into [master](https://codecov.io/gh/apache/apisix-dashboard/commit/a8352fafcce5f4abb158fcd14ed8658c51901643?el=desc) (a8352fa) will **increase** coverage by `1.57%`.
   > The diff coverage is `66.66%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/apisix-dashboard/pull/1072/graphs/tree.svg?width=650&height=150&src=pr&token=Q1HERXN96P)](https://codecov.io/gh/apache/apisix-dashboard/pull/1072?src=pr&el=tree)
   
   ```diff
   @@            Coverage Diff             @@
   ##           master    #1072      +/-   ##
   ==========================================
   + Coverage   40.44%   42.01%   +1.57%     
   ==========================================
     Files          27       28       +1     
     Lines        1627     1728     +101     
   ==========================================
   + Hits          658      726      +68     
   - Misses        874      901      +27     
   - Partials       95      101       +6     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/apisix-dashboard/pull/1072?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [api/filter/authentication.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1072/diff?src=pr&el=tree#diff-YXBpL2ZpbHRlci9hdXRoZW50aWNhdGlvbi5nbw==) | `0.00% <0.00%> (ø)` | |
   | [api/internal/handler/label/label.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1072/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvbGFiZWwvbGFiZWwuZ28=) | `68.00% <68.00%> (ø)` | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1072?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1072?src=pr&el=footer). Last update [a8352fa...1aac174](https://codecov.io/gh/apache/apisix-dashboard/pull/1072?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] tokers commented on a change in pull request #1072: feat: support labels list

Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #1072:
URL: https://github.com/apache/apisix-dashboard/pull/1072#discussion_r546193181



##########
File path: api/internal/handler/label/label.go
##########
@@ -0,0 +1,260 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package label
+
+import (
+	"encoding/json"
+	"fmt"
+	"github.com/shiningrush/droplet/data"

Review comment:
       Put this package after the standard libs.

##########
File path: api/internal/handler/label/label.go
##########
@@ -0,0 +1,260 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package label
+
+import (
+	"encoding/json"
+	"fmt"
+	"github.com/shiningrush/droplet/data"
+	"net/http"
+	"reflect"
+	"sort"
+	"strings"
+
+	"github.com/gin-gonic/gin"
+	"github.com/shiningrush/droplet"
+	"github.com/shiningrush/droplet/wrapper"
+	wgin "github.com/shiningrush/droplet/wrapper/gin"
+
+	"github.com/apisix/manager-api/internal/core/entity"
+	"github.com/apisix/manager-api/internal/core/store"
+	"github.com/apisix/manager-api/internal/handler"
+	"github.com/apisix/manager-api/internal/utils"
+)
+
+type Handler struct {
+	routeStore    store.Interface
+	serviceStore  store.Interface
+	upstreamStore store.Interface
+	sslStore      store.Interface
+	consumerStore store.Interface
+}
+
+var _ json.Marshaler = Pair{}
+
+type Pair struct {
+	Key string
+	Val string
+}
+
+func (p Pair) MarshalJSON() ([]byte, error) {
+	res := fmt.Sprintf("{\"%s\":\"%s\"}", p.Key, p.Val)

Review comment:
       It's not a good way, the JSON string will be broken if `p.Key` or `p.Val` has `"` in contents.

##########
File path: api/internal/handler/label/label.go
##########
@@ -0,0 +1,260 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package label
+
+import (
+	"encoding/json"
+	"fmt"
+	"github.com/shiningrush/droplet/data"
+	"net/http"
+	"reflect"
+	"sort"
+	"strings"
+
+	"github.com/gin-gonic/gin"
+	"github.com/shiningrush/droplet"
+	"github.com/shiningrush/droplet/wrapper"
+	wgin "github.com/shiningrush/droplet/wrapper/gin"
+
+	"github.com/apisix/manager-api/internal/core/entity"
+	"github.com/apisix/manager-api/internal/core/store"
+	"github.com/apisix/manager-api/internal/handler"
+	"github.com/apisix/manager-api/internal/utils"
+)
+
+type Handler struct {
+	routeStore    store.Interface
+	serviceStore  store.Interface
+	upstreamStore store.Interface
+	sslStore      store.Interface
+	consumerStore store.Interface
+}
+
+var _ json.Marshaler = Pair{}
+
+type Pair struct {
+	Key string
+	Val string
+}
+
+func (p Pair) MarshalJSON() ([]byte, error) {
+	res := fmt.Sprintf("{\"%s\":\"%s\"}", p.Key, p.Val)
+	return []byte(res), nil
+}
+
+func NewHandler() (handler.RouteRegister, error) {
+	return &Handler{
+		routeStore:    store.GetStore(store.HubKeyRoute),
+		serviceStore:  store.GetStore(store.HubKeyService),
+		upstreamStore: store.GetStore(store.HubKeyUpstream),
+		sslStore:      store.GetStore(store.HubKeySsl),
+		consumerStore: store.GetStore(store.HubKeyConsumer),
+	}, nil
+}
+
+func (h *Handler) ApplyRoute(r *gin.Engine) {
+	r.GET("/api/labels/:type", wgin.Wraps(h.List,
+		wrapper.InputType(reflect.TypeOf(ListInput{}))))
+}
+
+type ListInput struct {
+	Type  string `auto_read:"type,path" validate:"required"`
+	Label string `auto_read:"label,query"`
+	store.Pagination

Review comment:
       Well, we should put embed member at the top of struct definition.

##########
File path: api/internal/handler/label/label.go
##########
@@ -0,0 +1,260 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package label
+
+import (
+	"encoding/json"
+	"fmt"
+	"github.com/shiningrush/droplet/data"
+	"net/http"
+	"reflect"
+	"sort"
+	"strings"
+
+	"github.com/gin-gonic/gin"
+	"github.com/shiningrush/droplet"
+	"github.com/shiningrush/droplet/wrapper"
+	wgin "github.com/shiningrush/droplet/wrapper/gin"
+
+	"github.com/apisix/manager-api/internal/core/entity"
+	"github.com/apisix/manager-api/internal/core/store"
+	"github.com/apisix/manager-api/internal/handler"
+	"github.com/apisix/manager-api/internal/utils"
+)
+
+type Handler struct {
+	routeStore    store.Interface
+	serviceStore  store.Interface
+	upstreamStore store.Interface
+	sslStore      store.Interface
+	consumerStore store.Interface
+}
+
+var _ json.Marshaler = Pair{}
+
+type Pair struct {
+	Key string
+	Val string
+}
+
+func (p Pair) MarshalJSON() ([]byte, error) {
+	res := fmt.Sprintf("{\"%s\":\"%s\"}", p.Key, p.Val)
+	return []byte(res), nil
+}
+
+func NewHandler() (handler.RouteRegister, error) {
+	return &Handler{
+		routeStore:    store.GetStore(store.HubKeyRoute),
+		serviceStore:  store.GetStore(store.HubKeyService),
+		upstreamStore: store.GetStore(store.HubKeyUpstream),
+		sslStore:      store.GetStore(store.HubKeySsl),
+		consumerStore: store.GetStore(store.HubKeyConsumer),
+	}, nil
+}
+
+func (h *Handler) ApplyRoute(r *gin.Engine) {
+	r.GET("/api/labels/:type", wgin.Wraps(h.List,
+		wrapper.InputType(reflect.TypeOf(ListInput{}))))
+}
+
+type ListInput struct {
+	Type  string `auto_read:"type,path" validate:"required"`
+	Label string `auto_read:"label,query"`
+	store.Pagination
+}
+
+func getMatch(reqLabels, labels map[string]string) map[string]string {

Review comment:
       You can reference the label implementation of istio: https://github.com/istio/istio/blob/0c0cf2d6fb/pkg/config/labels/instance.go#L55.
   
   Encapsulate the getMatch as `SubsetOf` will be more semantic.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] starsz commented on a change in pull request #1072: feat: support labels list

Posted by GitBox <gi...@apache.org>.
starsz commented on a change in pull request #1072:
URL: https://github.com/apache/apisix-dashboard/pull/1072#discussion_r546229657



##########
File path: api/internal/handler/label/label.go
##########
@@ -0,0 +1,260 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package label
+
+import (
+	"encoding/json"
+	"fmt"
+	"github.com/shiningrush/droplet/data"

Review comment:
       Oh No. I think my goland plugin doesn't work.
   Let me fix it.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] starsz commented on a change in pull request #1072: feat: support labels list

Posted by GitBox <gi...@apache.org>.
starsz commented on a change in pull request #1072:
URL: https://github.com/apache/apisix-dashboard/pull/1072#discussion_r546174112



##########
File path: api/internal/handler/label/label.go
##########
@@ -0,0 +1,260 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package label
+
+import (
+	"encoding/json"
+	"fmt"
+	"github.com/shiningrush/droplet/data"
+	"net/http"
+	"reflect"
+	"sort"
+	"strings"
+
+	"github.com/gin-gonic/gin"
+	"github.com/shiningrush/droplet"
+	"github.com/shiningrush/droplet/wrapper"
+	wgin "github.com/shiningrush/droplet/wrapper/gin"
+
+	"github.com/apisix/manager-api/internal/core/entity"
+	"github.com/apisix/manager-api/internal/core/store"
+	"github.com/apisix/manager-api/internal/handler"
+	"github.com/apisix/manager-api/internal/utils"
+)
+
+type Handler struct {
+	routeStore    store.Interface
+	serviceStore  store.Interface
+	upstreamStore store.Interface
+	sslStore      store.Interface
+	consumerStore store.Interface
+}
+
+var _ json.Marshaler = Pair{}
+
+type Pair struct {
+	Key string
+	Val string
+}
+
+func (p Pair) MarshalJSON() ([]byte, error) {
+	res := fmt.Sprintf("{\"%s\":\"%s\"}", p.Key, p.Val)
+	return []byte(res), nil
+}
+
+func NewHandler() (handler.RouteRegister, error) {
+	return &Handler{
+		routeStore:    store.GetStore(store.HubKeyRoute),
+		serviceStore:  store.GetStore(store.HubKeyService),
+		upstreamStore: store.GetStore(store.HubKeyUpstream),
+		sslStore:      store.GetStore(store.HubKeySsl),
+		consumerStore: store.GetStore(store.HubKeyConsumer),
+	}, nil
+}
+
+func (h *Handler) ApplyRoute(r *gin.Engine) {
+	r.GET("/api/labels/:type", wgin.Wraps(h.List,
+		wrapper.InputType(reflect.TypeOf(ListInput{}))))
+}
+
+type ListInput struct {
+	Type  string `auto_read:"type,path" validate:"required"`
+	Label string `auto_read:"label,query"`
+	store.Pagination
+}
+
+func getMatch(reqLabels, labels map[string]string) map[string]string {
+	if len(reqLabels) == 0 {
+		return labels
+	}
+
+	var res = make(map[string]string)
+	for k, v := range labels {
+		l, exist := reqLabels[k]
+		if exist && ((l == "") || v == l) {
+			res[k] = v
+		}
+	}
+
+	return res
+}
+
+// swagger:operation GET /api/labels getLabelsList
+//
+// Return the labels list among `route,ssl,consumer,upstream,service`
+// according to the specified page number and page size, and can search labels by label.
+//
+// ---
+// produces:
+// - application/json
+// parameters:
+// - name: page
+//   in: query
+//   description: page number
+//   required: false
+//   type: integer
+// - name: page_size
+//   in: query
+//   description: page size
+//   required: false
+//   type: integer
+// - name: label
+//   in: query
+//   description: label filter of labels
+//   required: false
+//   type: string
+// responses:
+//   '0':
+//     description: list response
+//     schema:
+//       type: array
+//       items:
+//         "$ref": "#/definitions/service"
+//   default:
+//     description: unexpected error
+//     schema:
+//       "$ref": "#/definitions/ApiError"
+func (h *Handler) List(c droplet.Context) (interface{}, error) {
+	input := c.Input().(*ListInput)
+
+	typ := input.Type
+	reqLabels, err := utils.GenLabelMap(input.Label)
+	if err != nil {
+		return &data.SpecCodeResponse{StatusCode: http.StatusBadRequest},
+			fmt.Errorf("%s: \"%s\"", err.Error(), input.Label)
+	}
+
+	var items []interface{}
+	switch typ {

Review comment:
       Because the `type` is a keyword in golang.So I often use `typ` instead of `type`.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] juzhiyuan commented on a change in pull request #1072: feat: support labels list

Posted by GitBox <gi...@apache.org>.
juzhiyuan commented on a change in pull request #1072:
URL: https://github.com/apache/apisix-dashboard/pull/1072#discussion_r546535891



##########
File path: api/internal/handler/label/label.go
##########
@@ -0,0 +1,261 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package label
+
+import (
+	"encoding/json"
+	"fmt"
+	"net/http"
+	"reflect"
+	"sort"
+	"strconv"
+	"strings"
+
+	"github.com/gin-gonic/gin"
+	"github.com/shiningrush/droplet"
+	"github.com/shiningrush/droplet/data"
+	"github.com/shiningrush/droplet/wrapper"
+	wgin "github.com/shiningrush/droplet/wrapper/gin"
+
+	"github.com/apisix/manager-api/internal/core/entity"
+	"github.com/apisix/manager-api/internal/core/store"
+	"github.com/apisix/manager-api/internal/handler"
+	"github.com/apisix/manager-api/internal/utils"
+)
+
+type Handler struct {
+	routeStore    store.Interface
+	serviceStore  store.Interface
+	upstreamStore store.Interface
+	sslStore      store.Interface
+	consumerStore store.Interface
+}
+
+var _ json.Marshaler = Pair{}
+
+type Pair struct {
+	Key string
+	Val string
+}
+
+func (p Pair) MarshalJSON() ([]byte, error) {
+	res := fmt.Sprintf("{%s:%s}", strconv.Quote(p.Key), strconv.Quote(p.Val))
+	return []byte(res), nil
+}
+
+func NewHandler() (handler.RouteRegister, error) {
+	return &Handler{
+		routeStore:    store.GetStore(store.HubKeyRoute),
+		serviceStore:  store.GetStore(store.HubKeyService),
+		upstreamStore: store.GetStore(store.HubKeyUpstream),
+		sslStore:      store.GetStore(store.HubKeySsl),
+		consumerStore: store.GetStore(store.HubKeyConsumer),
+	}, nil
+}
+
+func (h *Handler) ApplyRoute(r *gin.Engine) {
+	r.GET("/api/labels/:type", wgin.Wraps(h.List,

Review comment:
       oh no I find there have a lot of APIs that start with `/api/`, just waiting for @starsz's reply.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] nic-chen commented on a change in pull request #1072: feat: support labels list

Posted by GitBox <gi...@apache.org>.
nic-chen commented on a change in pull request #1072:
URL: https://github.com/apache/apisix-dashboard/pull/1072#discussion_r546306982



##########
File path: api/test/e2e/label_test.go
##########
@@ -0,0 +1,229 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package e2e
+
+import (
+	"net/http"
+	"testing"
+)
+
+func TestLabel(t *testing.T) {
+	// Todo: test ssl after ssl bug fixed
+	tests := []HttpTestCase{
+		{
+			caseDesc: "config route",
+			Object:   ManagerApiExpect(t),
+			Path:     "/apisix/admin/routes/r1",
+			Method:   http.MethodPut,
+			Body: `{
+					"uri": "/hello",
+					"labels": {
+						"build":"16",
+						"env":"production",
+						"version":"v2"
+					},
+					"upstream": {
+						"type": "roundrobin",
+						"nodes": [{
+							"host": "172.16.238.20",
+							"port": 1980,
+							"weight": 1
+						}]
+					}
+				}`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc: "create consumer",
+			Object:   ManagerApiExpect(t),
+			Path:     "/apisix/admin/consumers/c1",
+			Method:   http.MethodPut,
+			Body: `{
+				"username": "jack",
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+				"labels": {
+					"build":"16",
+					"env":"production",
+					"version":"v3"
+				},
+				"desc": "test description"
+			}`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc: "create upstream",
+			Object:   ManagerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/upstreams/u1",
+			Body: `{
+				"nodes": [{
+					"host": "172.16.238.20",
+					"port": 1980,
+					"weight": 1
+				}],
+				"labels": {
+					"build":"17",
+					"env":"production",
+					"version":"v2"
+				},
+				"type": "roundrobin"
+			}`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc: "create service",
+			Object:   ManagerApiExpect(t),
+			Method:   http.MethodPost,
+			Path:     "/apisix/admin/services",
+			Body: `{
+				"id": "s1",
+				"plugins": {
+					"limit-count": {
+						"count": 2,
+						"time_window": 60,
+						"rejected_code": 503,
+						"key": "remote_addr"
+					}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": [{
+						"host": "39.97.63.215",
+						"port": 80,
+						"weight": 1
+					}]
+				},
+				"labels": {
+					"build":"16",
+					"env":"production",
+					"version":"v2",
+					"extra": "test"
+				}
+			}`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "get route label",
+			Object:       ManagerApiExpect(t),
+			Method:       http.MethodGet,
+			Headers:      map[string]string{"Authorization": token},
+			Path:         "/api/labels/route",
+			ExpectStatus: http.StatusOK,
+			ExpectBody:   "{\"build\":\"16\"},{\"env\":\"production\"},{\"version\":\"v2\"}",
+		},
+		{
+			caseDesc:     "get consumer label",
+			Object:       ManagerApiExpect(t),
+			Method:       http.MethodGet,
+			Headers:      map[string]string{"Authorization": token},
+			Path:         "/api/labels/consumer",
+			ExpectStatus: http.StatusOK,
+			ExpectBody:   "{\"build\":\"16\"},{\"env\":\"production\"},{\"version\":\"v3\"}",
+		},
+		{
+			caseDesc:     "get upstream label",
+			Object:       ManagerApiExpect(t),
+			Method:       http.MethodGet,
+			Headers:      map[string]string{"Authorization": token},
+			Path:         "/api/labels/upstream",
+			ExpectStatus: http.StatusOK,
+			ExpectBody:   "{\"build\":\"17\"},{\"env\":\"production\"},{\"version\":\"v2\"}",
+		},
+		{
+			caseDesc:     "get service label",
+			Object:       ManagerApiExpect(t),
+			Method:       http.MethodGet,
+			Headers:      map[string]string{"Authorization": token},
+			Path:         "/api/labels/service",
+			ExpectStatus: http.StatusOK,
+			ExpectBody:   "{\"build\":\"16\"},{\"env\":\"production\"},{\"extra\":\"test\"},{\"version\":\"v2\"}",
+		},
+		{
+			caseDesc:     "get all label",

Review comment:
       need test cases for paging and both searching and paging.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] codecov-io edited a comment on pull request #1072: feat: support labels list

Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on pull request #1072:
URL: https://github.com/apache/apisix-dashboard/pull/1072#issuecomment-748052557


   # [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1072?src=pr&el=h1) Report
   > Merging [#1072](https://codecov.io/gh/apache/apisix-dashboard/pull/1072?src=pr&el=desc) (0dd5460) into [master](https://codecov.io/gh/apache/apisix-dashboard/commit/a8352fafcce5f4abb158fcd14ed8658c51901643?el=desc) (a8352fa) will **increase** coverage by `1.39%`.
   > The diff coverage is `66.66%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/apisix-dashboard/pull/1072/graphs/tree.svg?width=650&height=150&src=pr&token=Q1HERXN96P)](https://codecov.io/gh/apache/apisix-dashboard/pull/1072?src=pr&el=tree)
   
   ```diff
   @@            Coverage Diff             @@
   ##           master    #1072      +/-   ##
   ==========================================
   + Coverage   40.44%   41.84%   +1.39%     
   ==========================================
     Files          27       28       +1     
     Lines        1627     1728     +101     
   ==========================================
   + Hits          658      723      +65     
   - Misses        874      902      +28     
   - Partials       95      103       +8     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/apisix-dashboard/pull/1072?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [api/filter/authentication.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1072/diff?src=pr&el=tree#diff-YXBpL2ZpbHRlci9hdXRoZW50aWNhdGlvbi5nbw==) | `0.00% <0.00%> (ø)` | |
   | [api/internal/handler/label/label.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1072/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvbGFiZWwvbGFiZWwuZ28=) | `68.00% <68.00%> (ø)` | |
   | [api/internal/core/store/validate.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1072/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvdmFsaWRhdGUuZ28=) | `57.62% <0.00%> (-2.26%)` | :arrow_down: |
   | [api/internal/core/store/store.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1072/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvc3RvcmUuZ28=) | `79.22% <0.00%> (+0.64%)` | :arrow_up: |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1072?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1072?src=pr&el=footer). Last update [a8352fa...0dd5460](https://codecov.io/gh/apache/apisix-dashboard/pull/1072?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] starsz commented on a change in pull request #1072: feat: support labels list

Posted by GitBox <gi...@apache.org>.
starsz commented on a change in pull request #1072:
URL: https://github.com/apache/apisix-dashboard/pull/1072#discussion_r546230538



##########
File path: api/internal/handler/label/label.go
##########
@@ -0,0 +1,260 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package label
+
+import (
+	"encoding/json"
+	"fmt"
+	"github.com/shiningrush/droplet/data"
+	"net/http"
+	"reflect"
+	"sort"
+	"strings"
+
+	"github.com/gin-gonic/gin"
+	"github.com/shiningrush/droplet"
+	"github.com/shiningrush/droplet/wrapper"
+	wgin "github.com/shiningrush/droplet/wrapper/gin"
+
+	"github.com/apisix/manager-api/internal/core/entity"
+	"github.com/apisix/manager-api/internal/core/store"
+	"github.com/apisix/manager-api/internal/handler"
+	"github.com/apisix/manager-api/internal/utils"
+)
+
+type Handler struct {
+	routeStore    store.Interface
+	serviceStore  store.Interface
+	upstreamStore store.Interface
+	sslStore      store.Interface
+	consumerStore store.Interface
+}
+
+var _ json.Marshaler = Pair{}
+
+type Pair struct {
+	Key string
+	Val string
+}
+
+func (p Pair) MarshalJSON() ([]byte, error) {
+	res := fmt.Sprintf("{\"%s\":\"%s\"}", p.Key, p.Val)

Review comment:
       I think it's ok because `key` and `val` come from req args. I will add some tests to ensure it.
   And do you have some suggestion?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] tokers commented on a change in pull request #1072: feat: support labels list

Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #1072:
URL: https://github.com/apache/apisix-dashboard/pull/1072#discussion_r546470736



##########
File path: api/internal/handler/label/label.go
##########
@@ -0,0 +1,260 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package label
+
+import (
+	"encoding/json"
+	"fmt"
+	"github.com/shiningrush/droplet/data"
+	"net/http"
+	"reflect"
+	"sort"
+	"strings"
+
+	"github.com/gin-gonic/gin"
+	"github.com/shiningrush/droplet"
+	"github.com/shiningrush/droplet/wrapper"
+	wgin "github.com/shiningrush/droplet/wrapper/gin"
+
+	"github.com/apisix/manager-api/internal/core/entity"
+	"github.com/apisix/manager-api/internal/core/store"
+	"github.com/apisix/manager-api/internal/handler"
+	"github.com/apisix/manager-api/internal/utils"
+)
+
+type Handler struct {
+	routeStore    store.Interface
+	serviceStore  store.Interface
+	upstreamStore store.Interface
+	sslStore      store.Interface
+	consumerStore store.Interface
+}
+
+var _ json.Marshaler = Pair{}
+
+type Pair struct {
+	Key string
+	Val string
+}
+
+func (p Pair) MarshalJSON() ([]byte, error) {
+	res := fmt.Sprintf("{\"%s\":\"%s\"}", p.Key, p.Val)

Review comment:
       No, it's a bug if you don't handle the special characters correctly in server side.
   
   That's OK if you can make sure that no `"` in key and value.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] starsz commented on a change in pull request #1072: feat: support labels list

Posted by GitBox <gi...@apache.org>.
starsz commented on a change in pull request #1072:
URL: https://github.com/apache/apisix-dashboard/pull/1072#discussion_r546478685



##########
File path: api/internal/handler/label/label.go
##########
@@ -0,0 +1,260 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package label
+
+import (
+	"encoding/json"
+	"fmt"
+	"github.com/shiningrush/droplet/data"
+	"net/http"
+	"reflect"
+	"sort"
+	"strings"
+
+	"github.com/gin-gonic/gin"
+	"github.com/shiningrush/droplet"
+	"github.com/shiningrush/droplet/wrapper"
+	wgin "github.com/shiningrush/droplet/wrapper/gin"
+
+	"github.com/apisix/manager-api/internal/core/entity"
+	"github.com/apisix/manager-api/internal/core/store"
+	"github.com/apisix/manager-api/internal/handler"
+	"github.com/apisix/manager-api/internal/utils"
+)
+
+type Handler struct {
+	routeStore    store.Interface
+	serviceStore  store.Interface
+	upstreamStore store.Interface
+	sslStore      store.Interface
+	consumerStore store.Interface
+}
+
+var _ json.Marshaler = Pair{}
+
+type Pair struct {
+	Key string
+	Val string
+}
+
+func (p Pair) MarshalJSON() ([]byte, error) {
+	res := fmt.Sprintf("{\"%s\":\"%s\"}", p.Key, p.Val)

Review comment:
       fixed. And add some tests.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] codecov-io edited a comment on pull request #1072: feat: support labels list

Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on pull request #1072:
URL: https://github.com/apache/apisix-dashboard/pull/1072#issuecomment-748052557


   # [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1072?src=pr&el=h1) Report
   > Merging [#1072](https://codecov.io/gh/apache/apisix-dashboard/pull/1072?src=pr&el=desc) (b6192e1) into [master](https://codecov.io/gh/apache/apisix-dashboard/commit/a8352fafcce5f4abb158fcd14ed8658c51901643?el=desc) (a8352fa) will **increase** coverage by `0.56%`.
   > The diff coverage is `70.00%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/apisix-dashboard/pull/1072/graphs/tree.svg?width=650&height=150&src=pr&token=Q1HERXN96P)](https://codecov.io/gh/apache/apisix-dashboard/pull/1072?src=pr&el=tree)
   
   ```diff
   @@            Coverage Diff             @@
   ##           master    #1072      +/-   ##
   ==========================================
   + Coverage   40.44%   41.00%   +0.56%     
   ==========================================
     Files          27       28       +1     
     Lines        1627     1773     +146     
   ==========================================
   + Hits          658      727      +69     
   - Misses        874      940      +66     
   - Partials       95      106      +11     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/apisix-dashboard/pull/1072?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [api/filter/authentication.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1072/diff?src=pr&el=tree#diff-YXBpL2ZpbHRlci9hdXRoZW50aWNhdGlvbi5nbw==) | `0.00% <ø> (ø)` | |
   | [api/internal/handler/label/label.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1072/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvbGFiZWwvbGFiZWwuZ28=) | `70.00% <70.00%> (ø)` | |
   | [api/internal/handler/route/route.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1072/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvcm91dGUvcm91dGUuZ28=) | `41.81% <0.00%> (-4.78%)` | :arrow_down: |
   | [api/internal/core/store/validate.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1072/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvdmFsaWRhdGUuZ28=) | `57.62% <0.00%> (-2.26%)` | :arrow_down: |
   | [api/filter/schema.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1072/diff?src=pr&el=tree#diff-YXBpL2ZpbHRlci9zY2hlbWEuZ28=) | `0.00% <0.00%> (ø)` | |
   | [api/internal/core/entity/entity.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1072/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvZW50aXR5L2VudGl0eS5nbw==) | `0.00% <0.00%> (ø)` | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1072?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1072?src=pr&el=footer). Last update [a8352fa...b6192e1](https://codecov.io/gh/apache/apisix-dashboard/pull/1072?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] nic-chen merged pull request #1072: feat: support labels list

Posted by GitBox <gi...@apache.org>.
nic-chen merged pull request #1072:
URL: https://github.com/apache/apisix-dashboard/pull/1072


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] juzhiyuan commented on a change in pull request #1072: feat: support labels list

Posted by GitBox <gi...@apache.org>.
juzhiyuan commented on a change in pull request #1072:
URL: https://github.com/apache/apisix-dashboard/pull/1072#discussion_r545862494



##########
File path: api/internal/handler/label/label.go
##########
@@ -0,0 +1,260 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package label
+
+import (
+	"encoding/json"
+	"fmt"
+	"github.com/shiningrush/droplet/data"
+	"net/http"
+	"reflect"
+	"sort"
+	"strings"
+
+	"github.com/gin-gonic/gin"
+	"github.com/shiningrush/droplet"
+	"github.com/shiningrush/droplet/wrapper"
+	wgin "github.com/shiningrush/droplet/wrapper/gin"
+
+	"github.com/apisix/manager-api/internal/core/entity"
+	"github.com/apisix/manager-api/internal/core/store"
+	"github.com/apisix/manager-api/internal/handler"
+	"github.com/apisix/manager-api/internal/utils"
+)
+
+type Handler struct {
+	routeStore    store.Interface
+	serviceStore  store.Interface
+	upstreamStore store.Interface
+	sslStore      store.Interface
+	consumerStore store.Interface
+}
+
+var _ json.Marshaler = Pair{}
+
+type Pair struct {
+	Key string
+	Val string
+}
+
+func (p Pair) MarshalJSON() ([]byte, error) {
+	res := fmt.Sprintf("{\"%s\":\"%s\"}", p.Key, p.Val)
+	return []byte(res), nil
+}
+
+func NewHandler() (handler.RouteRegister, error) {
+	return &Handler{
+		routeStore:    store.GetStore(store.HubKeyRoute),
+		serviceStore:  store.GetStore(store.HubKeyService),
+		upstreamStore: store.GetStore(store.HubKeyUpstream),
+		sslStore:      store.GetStore(store.HubKeySsl),
+		consumerStore: store.GetStore(store.HubKeyConsumer),
+	}, nil
+}
+
+func (h *Handler) ApplyRoute(r *gin.Engine) {
+	r.GET("/api/labels/:type", wgin.Wraps(h.List,
+		wrapper.InputType(reflect.TypeOf(ListInput{}))))
+}
+
+type ListInput struct {
+	Type  string `auto_read:"type,path" validate:"required"`
+	Label string `auto_read:"label,query"`
+	store.Pagination
+}
+
+func getMatch(reqLabels, labels map[string]string) map[string]string {
+	if len(reqLabels) == 0 {
+		return labels
+	}
+
+	var res = make(map[string]string)
+	for k, v := range labels {
+		l, exist := reqLabels[k]
+		if exist && ((l == "") || v == l) {
+			res[k] = v
+		}
+	}
+
+	return res
+}
+
+// swagger:operation GET /api/labels getLabelsList
+//
+// Return the labels list among `route,ssl,consumer,upstream,service`
+// according to the specified page number and page size, and can search labels by label.
+//
+// ---
+// produces:
+// - application/json
+// parameters:
+// - name: page
+//   in: query
+//   description: page number
+//   required: false
+//   type: integer
+// - name: page_size
+//   in: query
+//   description: page size
+//   required: false
+//   type: integer
+// - name: label
+//   in: query
+//   description: label filter of labels
+//   required: false
+//   type: string
+// responses:
+//   '0':
+//     description: list response
+//     schema:
+//       type: array
+//       items:
+//         "$ref": "#/definitions/service"
+//   default:
+//     description: unexpected error
+//     schema:
+//       "$ref": "#/definitions/ApiError"
+func (h *Handler) List(c droplet.Context) (interface{}, error) {
+	input := c.Input().(*ListInput)
+
+	typ := input.Type
+	reqLabels, err := utils.GenLabelMap(input.Label)
+	if err != nil {
+		return &data.SpecCodeResponse{StatusCode: http.StatusBadRequest},
+			fmt.Errorf("%s: \"%s\"", err.Error(), input.Label)
+	}
+
+	var items []interface{}
+	switch typ {

Review comment:
       shortname?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] starsz commented on a change in pull request #1072: feat: support labels list

Posted by GitBox <gi...@apache.org>.
starsz commented on a change in pull request #1072:
URL: https://github.com/apache/apisix-dashboard/pull/1072#discussion_r546558401



##########
File path: api/internal/handler/label/label.go
##########
@@ -0,0 +1,261 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package label
+
+import (
+	"encoding/json"
+	"fmt"
+	"net/http"
+	"reflect"
+	"sort"
+	"strconv"
+	"strings"
+
+	"github.com/gin-gonic/gin"
+	"github.com/shiningrush/droplet"
+	"github.com/shiningrush/droplet/data"
+	"github.com/shiningrush/droplet/wrapper"
+	wgin "github.com/shiningrush/droplet/wrapper/gin"
+
+	"github.com/apisix/manager-api/internal/core/entity"
+	"github.com/apisix/manager-api/internal/core/store"
+	"github.com/apisix/manager-api/internal/handler"
+	"github.com/apisix/manager-api/internal/utils"
+)
+
+type Handler struct {
+	routeStore    store.Interface
+	serviceStore  store.Interface
+	upstreamStore store.Interface
+	sslStore      store.Interface
+	consumerStore store.Interface
+}
+
+var _ json.Marshaler = Pair{}
+
+type Pair struct {
+	Key string
+	Val string
+}
+
+func (p Pair) MarshalJSON() ([]byte, error) {
+	res := fmt.Sprintf("{%s:%s}", strconv.Quote(p.Key), strconv.Quote(p.Val))
+	return []byte(res), nil
+}
+
+func NewHandler() (handler.RouteRegister, error) {
+	return &Handler{
+		routeStore:    store.GetStore(store.HubKeyRoute),
+		serviceStore:  store.GetStore(store.HubKeyService),
+		upstreamStore: store.GetStore(store.HubKeyUpstream),
+		sslStore:      store.GetStore(store.HubKeySsl),
+		consumerStore: store.GetStore(store.HubKeyConsumer),
+	}, nil
+}
+
+func (h *Handler) ApplyRoute(r *gin.Engine) {
+	r.GET("/api/labels/:type", wgin.Wraps(h.List,

Review comment:
       Oh.Sorry. I remember that we discuss use `/api/`?
   
   https://github.com/apache/apisix-dashboard/issues/861#issuecomment-738519671.
   
   Let me fix it.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] tokers commented on a change in pull request #1072: feat: support labels list

Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #1072:
URL: https://github.com/apache/apisix-dashboard/pull/1072#discussion_r546479709



##########
File path: api/internal/handler/label/label_test.go
##########
@@ -0,0 +1,312 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package label
+
+import (
+	"encoding/json"
+	"math/rand"
+	"testing"
+
+	"github.com/shiningrush/droplet"
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/mock"
+
+	"github.com/apisix/manager-api/internal/core/entity"
+	"github.com/apisix/manager-api/internal/core/store"
+)
+
+type testCase struct {
+	giveInput *ListInput
+	giveData  []interface{}
+	wantRet   interface{}
+}
+
+func TestPair_MarshalJSON(t *testing.T) {
+	p := Pair{Key: "test_key", Val: `test_val`}
+	content, err := json.Marshal(p)
+	assert.Nil(t, err, nil)
+	assert.Equal(t, `{"test_key":"test_val"}`, string(content))
+
+	p = Pair{Key: "test_key", Val: `test_val"`}
+	content, err = json.Marshal(p)
+	assert.Nil(t, err, nil)
+	assert.Equal(t, `{"test_key":"test_val\""}`, string(content))

Review comment:
       Can we also use `json.Unmarshal` to verify the manual constructed JSON?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] juzhiyuan commented on a change in pull request #1072: feat: support labels list

Posted by GitBox <gi...@apache.org>.
juzhiyuan commented on a change in pull request #1072:
URL: https://github.com/apache/apisix-dashboard/pull/1072#discussion_r546535503



##########
File path: api/internal/handler/label/label.go
##########
@@ -0,0 +1,261 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package label
+
+import (
+	"encoding/json"
+	"fmt"
+	"net/http"
+	"reflect"
+	"sort"
+	"strconv"
+	"strings"
+
+	"github.com/gin-gonic/gin"
+	"github.com/shiningrush/droplet"
+	"github.com/shiningrush/droplet/data"
+	"github.com/shiningrush/droplet/wrapper"
+	wgin "github.com/shiningrush/droplet/wrapper/gin"
+
+	"github.com/apisix/manager-api/internal/core/entity"
+	"github.com/apisix/manager-api/internal/core/store"
+	"github.com/apisix/manager-api/internal/handler"
+	"github.com/apisix/manager-api/internal/utils"
+)
+
+type Handler struct {
+	routeStore    store.Interface
+	serviceStore  store.Interface
+	upstreamStore store.Interface
+	sslStore      store.Interface
+	consumerStore store.Interface
+}
+
+var _ json.Marshaler = Pair{}
+
+type Pair struct {
+	Key string
+	Val string
+}
+
+func (p Pair) MarshalJSON() ([]byte, error) {
+	res := fmt.Sprintf("{%s:%s}", strconv.Quote(p.Key), strconv.Quote(p.Val))
+	return []byte(res), nil
+}
+
+func NewHandler() (handler.RouteRegister, error) {
+	return &Handler{
+		routeStore:    store.GetStore(store.HubKeyRoute),
+		serviceStore:  store.GetStore(store.HubKeyService),
+		upstreamStore: store.GetStore(store.HubKeyUpstream),
+		sslStore:      store.GetStore(store.HubKeySsl),
+		consumerStore: store.GetStore(store.HubKeyConsumer),
+	}, nil
+}
+
+func (h *Handler) ApplyRoute(r *gin.Engine) {
+	r.GET("/api/labels/:type", wgin.Wraps(h.List,

Review comment:
       @starsz maybe not family with that rule? Let's help to update it.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] nic-chen commented on a change in pull request #1072: feat: support labels list

Posted by GitBox <gi...@apache.org>.
nic-chen commented on a change in pull request #1072:
URL: https://github.com/apache/apisix-dashboard/pull/1072#discussion_r546534550



##########
File path: api/internal/handler/label/label.go
##########
@@ -0,0 +1,261 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package label
+
+import (
+	"encoding/json"
+	"fmt"
+	"net/http"
+	"reflect"
+	"sort"
+	"strconv"
+	"strings"
+
+	"github.com/gin-gonic/gin"
+	"github.com/shiningrush/droplet"
+	"github.com/shiningrush/droplet/data"
+	"github.com/shiningrush/droplet/wrapper"
+	wgin "github.com/shiningrush/droplet/wrapper/gin"
+
+	"github.com/apisix/manager-api/internal/core/entity"
+	"github.com/apisix/manager-api/internal/core/store"
+	"github.com/apisix/manager-api/internal/handler"
+	"github.com/apisix/manager-api/internal/utils"
+)
+
+type Handler struct {
+	routeStore    store.Interface
+	serviceStore  store.Interface
+	upstreamStore store.Interface
+	sslStore      store.Interface
+	consumerStore store.Interface
+}
+
+var _ json.Marshaler = Pair{}
+
+type Pair struct {
+	Key string
+	Val string
+}
+
+func (p Pair) MarshalJSON() ([]byte, error) {
+	res := fmt.Sprintf("{%s:%s}", strconv.Quote(p.Key), strconv.Quote(p.Val))
+	return []byte(res), nil
+}
+
+func NewHandler() (handler.RouteRegister, error) {
+	return &Handler{
+		routeStore:    store.GetStore(store.HubKeyRoute),
+		serviceStore:  store.GetStore(store.HubKeyService),
+		upstreamStore: store.GetStore(store.HubKeyUpstream),
+		sslStore:      store.GetStore(store.HubKeySsl),
+		consumerStore: store.GetStore(store.HubKeyConsumer),
+	}, nil
+}
+
+func (h *Handler) ApplyRoute(r *gin.Engine) {
+	r.GET("/api/labels/:type", wgin.Wraps(h.List,

Review comment:
       why not use prefix `/apisix/admin` here ?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] starsz commented on a change in pull request #1072: feat: support labels list

Posted by GitBox <gi...@apache.org>.
starsz commented on a change in pull request #1072:
URL: https://github.com/apache/apisix-dashboard/pull/1072#discussion_r546230550



##########
File path: api/internal/handler/label/label.go
##########
@@ -0,0 +1,260 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package label
+
+import (
+	"encoding/json"
+	"fmt"
+	"github.com/shiningrush/droplet/data"
+	"net/http"
+	"reflect"
+	"sort"
+	"strings"
+
+	"github.com/gin-gonic/gin"
+	"github.com/shiningrush/droplet"
+	"github.com/shiningrush/droplet/wrapper"
+	wgin "github.com/shiningrush/droplet/wrapper/gin"
+
+	"github.com/apisix/manager-api/internal/core/entity"
+	"github.com/apisix/manager-api/internal/core/store"
+	"github.com/apisix/manager-api/internal/handler"
+	"github.com/apisix/manager-api/internal/utils"
+)
+
+type Handler struct {
+	routeStore    store.Interface
+	serviceStore  store.Interface
+	upstreamStore store.Interface
+	sslStore      store.Interface
+	consumerStore store.Interface
+}
+
+var _ json.Marshaler = Pair{}
+
+type Pair struct {
+	Key string
+	Val string
+}
+
+func (p Pair) MarshalJSON() ([]byte, error) {
+	res := fmt.Sprintf("{\"%s\":\"%s\"}", p.Key, p.Val)

Review comment:
       I think it's ok because `key` and `val` come from req args. I will add some tests to ensure it.
   And do you have some suggestions?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] starsz commented on a change in pull request #1072: feat: support labels list

Posted by GitBox <gi...@apache.org>.
starsz commented on a change in pull request #1072:
URL: https://github.com/apache/apisix-dashboard/pull/1072#discussion_r546230538



##########
File path: api/internal/handler/label/label.go
##########
@@ -0,0 +1,260 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package label
+
+import (
+	"encoding/json"
+	"fmt"
+	"github.com/shiningrush/droplet/data"
+	"net/http"
+	"reflect"
+	"sort"
+	"strings"
+
+	"github.com/gin-gonic/gin"
+	"github.com/shiningrush/droplet"
+	"github.com/shiningrush/droplet/wrapper"
+	wgin "github.com/shiningrush/droplet/wrapper/gin"
+
+	"github.com/apisix/manager-api/internal/core/entity"
+	"github.com/apisix/manager-api/internal/core/store"
+	"github.com/apisix/manager-api/internal/handler"
+	"github.com/apisix/manager-api/internal/utils"
+)
+
+type Handler struct {
+	routeStore    store.Interface
+	serviceStore  store.Interface
+	upstreamStore store.Interface
+	sslStore      store.Interface
+	consumerStore store.Interface
+}
+
+var _ json.Marshaler = Pair{}
+
+type Pair struct {
+	Key string
+	Val string
+}
+
+func (p Pair) MarshalJSON() ([]byte, error) {
+	res := fmt.Sprintf("{\"%s\":\"%s\"}", p.Key, p.Val)

Review comment:
       I think it's ok because `key` and `val` come from req args. I will add some tests to ensure it.
   And do you have some suggestion?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] starsz commented on a change in pull request #1072: feat: support labels list

Posted by GitBox <gi...@apache.org>.
starsz commented on a change in pull request #1072:
URL: https://github.com/apache/apisix-dashboard/pull/1072#discussion_r546230572



##########
File path: api/internal/handler/label/label.go
##########
@@ -0,0 +1,260 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package label
+
+import (
+	"encoding/json"
+	"fmt"
+	"github.com/shiningrush/droplet/data"
+	"net/http"
+	"reflect"
+	"sort"
+	"strings"
+
+	"github.com/gin-gonic/gin"
+	"github.com/shiningrush/droplet"
+	"github.com/shiningrush/droplet/wrapper"
+	wgin "github.com/shiningrush/droplet/wrapper/gin"
+
+	"github.com/apisix/manager-api/internal/core/entity"
+	"github.com/apisix/manager-api/internal/core/store"
+	"github.com/apisix/manager-api/internal/handler"
+	"github.com/apisix/manager-api/internal/utils"
+)
+
+type Handler struct {
+	routeStore    store.Interface
+	serviceStore  store.Interface
+	upstreamStore store.Interface
+	sslStore      store.Interface
+	consumerStore store.Interface
+}
+
+var _ json.Marshaler = Pair{}
+
+type Pair struct {
+	Key string
+	Val string
+}
+
+func (p Pair) MarshalJSON() ([]byte, error) {
+	res := fmt.Sprintf("{\"%s\":\"%s\"}", p.Key, p.Val)
+	return []byte(res), nil
+}
+
+func NewHandler() (handler.RouteRegister, error) {
+	return &Handler{
+		routeStore:    store.GetStore(store.HubKeyRoute),
+		serviceStore:  store.GetStore(store.HubKeyService),
+		upstreamStore: store.GetStore(store.HubKeyUpstream),
+		sslStore:      store.GetStore(store.HubKeySsl),
+		consumerStore: store.GetStore(store.HubKeyConsumer),
+	}, nil
+}
+
+func (h *Handler) ApplyRoute(r *gin.Engine) {
+	r.GET("/api/labels/:type", wgin.Wraps(h.List,
+		wrapper.InputType(reflect.TypeOf(ListInput{}))))
+}
+
+type ListInput struct {
+	Type  string `auto_read:"type,path" validate:"required"`
+	Label string `auto_read:"label,query"`
+	store.Pagination

Review comment:
       OK.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] starsz commented on a change in pull request #1072: feat: support labels list

Posted by GitBox <gi...@apache.org>.
starsz commented on a change in pull request #1072:
URL: https://github.com/apache/apisix-dashboard/pull/1072#discussion_r546235393



##########
File path: api/internal/handler/label/label.go
##########
@@ -0,0 +1,260 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package label
+
+import (
+	"encoding/json"
+	"fmt"
+	"github.com/shiningrush/droplet/data"
+	"net/http"
+	"reflect"
+	"sort"
+	"strings"
+
+	"github.com/gin-gonic/gin"
+	"github.com/shiningrush/droplet"
+	"github.com/shiningrush/droplet/wrapper"
+	wgin "github.com/shiningrush/droplet/wrapper/gin"
+
+	"github.com/apisix/manager-api/internal/core/entity"
+	"github.com/apisix/manager-api/internal/core/store"
+	"github.com/apisix/manager-api/internal/handler"
+	"github.com/apisix/manager-api/internal/utils"
+)
+
+type Handler struct {
+	routeStore    store.Interface
+	serviceStore  store.Interface
+	upstreamStore store.Interface
+	sslStore      store.Interface
+	consumerStore store.Interface
+}
+
+var _ json.Marshaler = Pair{}
+
+type Pair struct {
+	Key string
+	Val string
+}
+
+func (p Pair) MarshalJSON() ([]byte, error) {
+	res := fmt.Sprintf("{\"%s\":\"%s\"}", p.Key, p.Val)

Review comment:
       I think it's not a problem. If '"' in contents, Json.Marshal will return an error.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] starsz commented on a change in pull request #1072: feat: support labels list

Posted by GitBox <gi...@apache.org>.
starsz commented on a change in pull request #1072:
URL: https://github.com/apache/apisix-dashboard/pull/1072#discussion_r546230096



##########
File path: api/internal/handler/label/label.go
##########
@@ -0,0 +1,260 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package label
+
+import (
+	"encoding/json"
+	"fmt"
+	"github.com/shiningrush/droplet/data"
+	"net/http"
+	"reflect"
+	"sort"
+	"strings"
+
+	"github.com/gin-gonic/gin"
+	"github.com/shiningrush/droplet"
+	"github.com/shiningrush/droplet/wrapper"
+	wgin "github.com/shiningrush/droplet/wrapper/gin"
+
+	"github.com/apisix/manager-api/internal/core/entity"
+	"github.com/apisix/manager-api/internal/core/store"
+	"github.com/apisix/manager-api/internal/handler"
+	"github.com/apisix/manager-api/internal/utils"
+)
+
+type Handler struct {
+	routeStore    store.Interface
+	serviceStore  store.Interface
+	upstreamStore store.Interface
+	sslStore      store.Interface
+	consumerStore store.Interface
+}
+
+var _ json.Marshaler = Pair{}
+
+type Pair struct {
+	Key string
+	Val string
+}
+
+func (p Pair) MarshalJSON() ([]byte, error) {
+	res := fmt.Sprintf("{\"%s\":\"%s\"}", p.Key, p.Val)
+	return []byte(res), nil
+}
+
+func NewHandler() (handler.RouteRegister, error) {
+	return &Handler{
+		routeStore:    store.GetStore(store.HubKeyRoute),
+		serviceStore:  store.GetStore(store.HubKeyService),
+		upstreamStore: store.GetStore(store.HubKeyUpstream),
+		sslStore:      store.GetStore(store.HubKeySsl),
+		consumerStore: store.GetStore(store.HubKeyConsumer),
+	}, nil
+}
+
+func (h *Handler) ApplyRoute(r *gin.Engine) {
+	r.GET("/api/labels/:type", wgin.Wraps(h.List,
+		wrapper.InputType(reflect.TypeOf(ListInput{}))))
+}
+
+type ListInput struct {
+	Type  string `auto_read:"type,path" validate:"required"`
+	Label string `auto_read:"label,query"`
+	store.Pagination
+}
+
+func getMatch(reqLabels, labels map[string]string) map[string]string {

Review comment:
       Good idea.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix-dashboard] codecov-io edited a comment on pull request #1072: feat: support labels list

Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on pull request #1072:
URL: https://github.com/apache/apisix-dashboard/pull/1072#issuecomment-748052557


   # [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1072?src=pr&el=h1) Report
   > Merging [#1072](https://codecov.io/gh/apache/apisix-dashboard/pull/1072?src=pr&el=desc) (cdc215a) into [master](https://codecov.io/gh/apache/apisix-dashboard/commit/a8352fafcce5f4abb158fcd14ed8658c51901643?el=desc) (a8352fa) will **increase** coverage by `1.38%`.
   > The diff coverage is `68.62%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/apisix-dashboard/pull/1072/graphs/tree.svg?width=650&height=150&src=pr&token=Q1HERXN96P)](https://codecov.io/gh/apache/apisix-dashboard/pull/1072?src=pr&el=tree)
   
   ```diff
   @@            Coverage Diff             @@
   ##           master    #1072      +/-   ##
   ==========================================
   + Coverage   40.44%   41.82%   +1.38%     
   ==========================================
     Files          27       28       +1     
     Lines        1627     1738     +111     
   ==========================================
   + Hits          658      727      +69     
   - Misses        874      905      +31     
   - Partials       95      106      +11     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/apisix-dashboard/pull/1072?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [api/filter/authentication.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1072/diff?src=pr&el=tree#diff-YXBpL2ZpbHRlci9hdXRoZW50aWNhdGlvbi5nbw==) | `0.00% <0.00%> (ø)` | |
   | [api/internal/handler/label/label.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1072/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvbGFiZWwvbGFiZWwuZ28=) | `70.00% <70.00%> (ø)` | |
   | [api/internal/core/store/validate.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1072/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvdmFsaWRhdGUuZ28=) | `57.62% <0.00%> (-2.26%)` | :arrow_down: |
   | [api/internal/handler/route/route.go](https://codecov.io/gh/apache/apisix-dashboard/pull/1072/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvcm91dGUvcm91dGUuZ28=) | `45.77% <0.00%> (-0.83%)` | :arrow_down: |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1072?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/1072?src=pr&el=footer). Last update [a8352fa...ca0db01](https://codecov.io/gh/apache/apisix-dashboard/pull/1072?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org