分页查询
This commit is contained in:
		@@ -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]
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user