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 ce06449  feat: add paging to the listUpstreamName (#443)
ce06449 is described below

commit ce064494ab80f70fcac3976f405776ef3a9eafd9
Author: liuxiran <belovedx...@126.com>
AuthorDate: Sat Sep 5 21:04:49 2020 +0800

    feat: add paging to the listUpstreamName (#443)
---
 api/route/upstream.go | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/api/route/upstream.go b/api/route/upstream.go
index 0bff0cb..0135a85 100644
--- a/api/route/upstream.go
+++ b/api/route/upstream.go
@@ -74,10 +74,17 @@ func isUpstreamExist(c *gin.Context) {
 }
 
 func listUpstreamName(c *gin.Context) {
+       size, _ := strconv.Atoi(c.Query("size"))
+       page, _ := strconv.Atoi(c.Query("page"))
        db := conf.DB()
        upstreamList := []service.UpstreamDao{}
        var count int
-       if err := 
db.Order("name").Table("upstreams").Find(&upstreamList).Count(&count).Error; 
err != nil {
+       if size == 0 || page == 0 {
+               db = db.Order("name").Table("upstreams")
+       } else {
+               db = db.Order("name").Table("upstreams").Offset((page - 1) * 
size).Limit(size)
+       }
+       if err := db.Find(&upstreamList).Count(&count).Error; err != nil {
                e := errno.FromMessage(errno.UpstreamRequestError, err.Error())
                logger.Error(e.Msg)
                c.AbortWithStatusJSON(http.StatusInternalServerError, 
e.Response())

Reply via email to