-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
49 lines (41 loc) · 1.37 KB
/
app.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"context"
"fmt"
"gitHub.com/apigee/apigee-gqlserver/gqlserver/schema"
"github.com/graph-gophers/graphql-go/relay"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"log"
"net/http"
"time"
pb "gitHub.com/apigee/apigee-gqlserver/greeting"
)
// printFeature gets the feature for the given point.
func sayHello(client pb.GreetingServiceClient, message *pb.Message) {
log.Printf("Say Hello with message (%v)", message.Body)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
greeting, err := client.SayHello(ctx, message)
if err != nil {
log.Fatalf("client.SayHello failed: %v", err)
}
log.Println(greeting)
}
func main() {
conn, err := grpc.Dial("localhost:9000", grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("fail to dial: %v", err)
}
defer conn.Close()
client := pb.NewGreetingServiceClient(conn)
sayHello(client, &pb.Message{Body: "World!"})
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Status: OK")
})
//gqlSchema := graphql.MustParseSchema(, &resolver.Resolver{})
//http.Handle("/graphql", &relay.Handler{Schema: schema.GetSchema()})
http.Handle("/graphql", &relay.Handler{Schema: schema.GetGqlSchema()})
fmt.Println("server running at port 8000")
log.Fatalln(http.ListenAndServe(":8000", nil))
}