You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by ju...@apache.org on 2020/09/05 13:04:58 UTC
[apisix-dashboard] branch master updated: feat: add paging to the
listUpstreamName (#443)
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 <be...@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())