graphql
This commit is contained in:
		
							
								
								
									
										26
									
								
								bin/main.go
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								bin/main.go
									
									
									
									
									
								
							@@ -17,6 +17,7 @@ import (
 | 
			
		||||
 | 
			
		||||
	"git.satori.love/gameui/webp/models"
 | 
			
		||||
	_ "github.com/go-sql-driver/mysql"
 | 
			
		||||
	"github.com/graphql-go/graphql"
 | 
			
		||||
	"github.com/milvus-io/milvus-sdk-go/v2/entity"
 | 
			
		||||
	"github.com/spf13/viper"
 | 
			
		||||
)
 | 
			
		||||
@@ -175,11 +176,32 @@ func main() {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Schema
 | 
			
		||||
	schema, err := models.NewSchema()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Fatalf("failed to create new schema, error: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
		defer LogComponent(time.Now().UnixNano(), r) // 最后打印日志
 | 
			
		||||
		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.Marshal(result)
 | 
			
		||||
		fmt.Printf("%s \n", rJSON)
 | 
			
		||||
		w.Write(rJSON)
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	http.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
		defer LogComponent(time.Now().UnixNano(), r) // 最后打印日志
 | 
			
		||||
		http.Error(w, "Not Found", http.StatusNotFound)
 | 
			
		||||
@@ -249,8 +271,8 @@ func main() {
 | 
			
		||||
		// 私域: (自己的图片, 自己的文章, 自己的精选集, 点赞收藏精选集)
 | 
			
		||||
		// 条件查询(模糊搜索, 时间区间, 作者, 标签, 分类, 精选集, 状态, 置顶, 模糊权重)(权重规则:权重指数)
 | 
			
		||||
		// 条件筛选(交集, 并集, 差集, 子集)
 | 
			
		||||
		// 排序
 | 
			
		||||
		// 分页
 | 
			
		||||
		// 文字搜索支持翻页
 | 
			
		||||
		// 文字搜索支持与按颜色筛选混合
 | 
			
		||||
 | 
			
		||||
		// 获取查询条件(忽略空值)
 | 
			
		||||
		QueryConditions := func(key string) (list []string) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user