分页参数

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 ( import (
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"log" "log"
"net/http" "net/http"
@@ -33,13 +34,14 @@ var SearchItems = &graphql.Field{
}, },
}), }),
Args: graphql.FieldConfigArgument{ Args: graphql.FieldConfigArgument{
"name": &graphql.ArgumentConfig{Type: graphql.String, Description: "按指定字符筛选"}, "name": &graphql.ArgumentConfig{Type: graphql.String, Description: "按指定字符筛选"},
"first": &graphql.ArgumentConfig{Type: graphql.Int, Description: "翻页参数(傳回清單中的前n個元素)", DefaultValue: 10},
}, },
Resolve: func(p graphql.ResolveParams) (interface{}, error) { Resolve: func(p graphql.ResolveParams) (interface{}, error) {
var searchs []Search var searchs []Search
// 发送 GET 请求 // 发送 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 { if err != nil {
log.Fatalf("Failed to fetch data: %v", err) log.Fatalf("Failed to fetch data: %v", err)
} }