-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.go
More file actions
58 lines (48 loc) · 1.34 KB
/
Copy pathserver.go
File metadata and controls
58 lines (48 loc) · 1.34 KB
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
50
51
52
53
54
55
56
57
58
// Package main provides the entry point for the SP API GraphQL server.
package main
import (
"flag"
"log"
"net/http"
"os"
"time"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/playground"
"github.com/Rusty-Alucard/sp_api/config"
"github.com/Rusty-Alucard/sp_api/graph/generated"
"github.com/Rusty-Alucard/sp_api/graph/resolver"
)
const (
defaultPort = "8080"
readTimeout = 15 * time.Second
writeTimeout = 15 * time.Second
idleTimeout = 60 * time.Second
)
func main() {
env := flag.String("e", "local", "")
flag.Parse()
// config初期化
if err := config.Init(*env); err != nil {
panic(err)
}
port, ret := os.LookupEnv("PORT")
if !ret {
port = defaultPort
}
srv := handler.NewDefaultServer(generated.NewExecutableSchema(generated.Config{Resolvers: &resolver.Resolver{
EventUseCase: InitializeEventUseCase(),
TeamUseCase: InitializeTeamUseCase(),
}}))
http.Handle("/", playground.Handler("GraphQL playground", "/query"))
http.Handle("/query", srv)
// Create HTTP server with timeout configuration
server := &http.Server{
Addr: ":" + port,
Handler: nil,
ReadTimeout: readTimeout,
WriteTimeout: writeTimeout,
IdleTimeout: idleTimeout,
}
log.Printf("connect to http://localhost:%s/ for GraphQL playground", port)
log.Fatal(server.ListenAndServe())
}