Files
webp/demo/main.go
2023-11-20 23:25:18 +08:00

36 lines
784 B
Go

package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"runtime"
"git.satori.love/gameui/webp/api"
"github.com/graphql-go/graphql"
)
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
schema, err := api.NewSchema()
if err != nil {
log.Fatalln("创建Schema失败", err)
}
http.HandleFunc("/api", func(w http.ResponseWriter, r *http.Request) {
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, "", " ")
w.Write(rJSON)
})
http.ListenAndServe(":6001", nil)
}