MCPcopy Create free account
hub / github.com/devfullcycle/goexpert / main

Function main

13-GraphQL/cmd/server/server.go:19–44  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

17const defaultPort = "8080"
18
19func main() {
20 db, err := sql.Open("sqlite3", "./data.db")
21 if err != nil {
22 log.Fatalf("failed to open database: %v", err)
23 }
24 defer db.Close()
25
26 categoryDb := database.NewCategory(db)
27 courseDb := database.NewCourse(db)
28
29 port := os.Getenv("PORT")
30 if port == "" {
31 port = defaultPort
32 }
33
34 srv := handler.NewDefaultServer(generated.NewExecutableSchema(generated.Config{Resolvers: &graph.Resolver{
35 CategoryDB: categoryDb,
36 CourseDB: courseDb,
37 }}))
38
39 http.Handle("/", playground.Handler("GraphQL playground", "/query"))
40 http.Handle("/query", srv)
41
42 log.Printf("connect to http://localhost:%s/ for GraphQL playground", port)
43 log.Fatal(http.ListenAndServe(":"+port, nil))
44}

Callers

nothing calls this directly

Calls 1

HandleMethod · 0.65

Tested by

no test coverage detected