翻页
This commit is contained in:
		
							
								
								
									
										35
									
								
								bin/main.go
									
									
									
									
									
								
							
							
						
						
									
										35
									
								
								bin/main.go
									
									
									
									
									
								
							@@ -18,7 +18,7 @@ import (
 | 
			
		||||
	"git.satori.love/gameui/webp/api"
 | 
			
		||||
	"git.satori.love/gameui/webp/models"
 | 
			
		||||
	_ "github.com/go-sql-driver/mysql"
 | 
			
		||||
	"github.com/graphql-go/graphql"
 | 
			
		||||
	"github.com/graphql-go/handler"
 | 
			
		||||
	"github.com/milvus-io/milvus-sdk-go/v2/entity"
 | 
			
		||||
	"github.com/spf13/viper"
 | 
			
		||||
)
 | 
			
		||||
@@ -210,19 +210,24 @@ func main() {
 | 
			
		||||
		w.Write([]byte("Hello World!"))
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	http.HandleFunc("/api", func(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
		defer LogComponent(time.Now().UnixNano(), r) // 最后打印日志
 | 
			
		||||
		query := r.URL.Query().Get("query")
 | 
			
		||||
		params := graphql.Params{Schema: schema, RequestString: query}
 | 
			
		||||
		result := graphql.Do(params)
 | 
			
		||||
		if len(result.Errors) > 0 {
 | 
			
		||||
			fmt.Printf("failed to execute graphql operation, errors: %+v", result.Errors)
 | 
			
		||||
			http.Error(w, result.Errors[0].Error(), 500)
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
		rJSON, _ := json.MarshalIndent(result.Data, "", "  ")
 | 
			
		||||
		w.Write(rJSON)
 | 
			
		||||
	})
 | 
			
		||||
	http.Handle("/graphql", handler.New(&handler.Config{
 | 
			
		||||
		Schema: &schema,
 | 
			
		||||
		Pretty: true,
 | 
			
		||||
	}))
 | 
			
		||||
 | 
			
		||||
	//http.HandleFunc("/api", func(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
	//	defer LogComponent(time.Now().UnixNano(), r) // 最后打印日志
 | 
			
		||||
	//	query := r.URL.Query().Get("query")
 | 
			
		||||
	//	params := graphql.Params{Schema: schema, RequestString: query}
 | 
			
		||||
	//	result := graphql.Do(params)
 | 
			
		||||
	//	if len(result.Errors) > 0 {
 | 
			
		||||
	//		fmt.Printf("failed to execute graphql operation, errors: %+v", result.Errors)
 | 
			
		||||
	//		http.Error(w, result.Errors[0].Error(), 500)
 | 
			
		||||
	//		return
 | 
			
		||||
	//	}
 | 
			
		||||
	//	rJSON, _ := json.MarshalIndent(result.Data, "", "  ")
 | 
			
		||||
	//	w.Write(rJSON)
 | 
			
		||||
	//})
 | 
			
		||||
 | 
			
		||||
	http.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
		defer LogComponent(time.Now().UnixNano(), r) // 最后打印日志
 | 
			
		||||
@@ -320,7 +325,7 @@ func main() {
 | 
			
		||||
		// 如果是查询 text, 直接从 Elasticsearch 返回结果
 | 
			
		||||
		var text_ids []string
 | 
			
		||||
		if text := QueryConditions("text"); len(text) > 0 {
 | 
			
		||||
			text_ids := models.ElasticsearchSearch(strings.Join(text, " ")).GetIDList()
 | 
			
		||||
			text_ids := models.ElasticsearchSearch(strings.Join(text, " ")).GetIDList(0, 0, 0, 0)
 | 
			
		||||
			if len(text_ids) > 0 {
 | 
			
		||||
				conditions.WriteString(fmt.Sprintf(" WHERE id IN (%s)", strings.Trim(strings.Replace(fmt.Sprint(text_ids), " ", ",", -1), "[]")))
 | 
			
		||||
			} else {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user