From a18c2228789ff878a11925ded2c96f50212c2318 Mon Sep 17 00:00:00 2001 From: loshiqi <553578653@qq.com> Date: Fri, 4 Nov 2022 13:49:45 +0800 Subject: [PATCH] =?UTF-8?q?map=E5=88=87=E7=89=87=E6=8A=8Afor=E6=94=B9?= =?UTF-8?q?=E6=88=90=E6=88=AA=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- map.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/map.go b/map.go index 6c0f85e..ff6d367 100644 --- a/map.go +++ b/map.go @@ -263,16 +263,17 @@ func MapSort(order, val, val_type string, MapDate []map[string]interface{}) ([]m return res, nil } func MapPage(pageNum, pageSize int, MapDate []map[string]interface{}) []map[string]interface{} { - list := []map[string]interface{}{} stat := (pageNum - 1) * pageSize - end := stat + pageSize - 1 - for k, v := range MapDate { - if k >= stat && k <= end { - list = append(list, v) - } - if k > end { - break - } + end := stat + pageSize + count := len(MapDate) + if stat >= count { + return []map[string]interface{}{} + } + if end >= count { + end = count + } + if stat < 0 || end < 0 { + return []map[string]interface{}{} } - return list + return MapDate[stat:end] }