分页参数

This commit is contained in:
2024-12-16 13:56:34 +08:00
parent 7d28cdac53
commit eb7ea4acc3

View File

@@ -2,6 +2,7 @@ package api
import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
@@ -34,12 +35,13 @@ var SearchItems = &graphql.Field{
}),
Args: graphql.FieldConfigArgument{
"name": &graphql.ArgumentConfig{Type: graphql.String, Description: "按指定字符筛选"},
"first": &graphql.ArgumentConfig{Type: graphql.Int, Description: "翻页参数(傳回清單中的前n個元素)", DefaultValue: 10},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
var searchs []Search
// 发送 GET 请求
resp, err := http.Get("http://localhost:6005/api/get_search/hot")
resp, err := http.Get(fmt.Sprintf("http://localhost:6005/api/get_search/hot?page=%d", p.Args["first"]))
if err != nil {
log.Fatalf("Failed to fetch data: %v", err)
}