分页查询

This commit is contained in:
2024-11-05 18:42:54 +08:00
parent 13ec042ddf
commit da6913eaba
7 changed files with 178 additions and 162 deletions

View File

@@ -9,6 +9,7 @@ import (
"log"
"net/http"
"net/url"
"strconv"
)
var (
@@ -63,13 +64,14 @@ type Response struct {
} `json:"hits"`
}
func (res Response) ToIDList(first, last int, after, before string) (id_list []string) {
func (res Response) ToIDList(first, last int, after, before int) (id_list []int) {
for _, hit := range res.Hits.Hits {
id_list = append(id_list, hit.ID)
num, _ := strconv.Atoi(hit.ID)
id_list = append(id_list, num)
}
// 如果 after 不为 0, 从这个ID开始向后取切片
if after != "" {
if after != 0 {
for i, id := range id_list {
if id == after {
id_list = id_list[i+1:]
@@ -79,7 +81,7 @@ func (res Response) ToIDList(first, last int, after, before string) (id_list []s
}
// 如果 before 不为 0, 从这个ID开始向前取切片
if before != "" {
if before != 0 {
for i, id := range id_list {
if id == before {
id_list = id_list[:i]