-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
82 lines (71 loc) · 2.67 KB
/
main.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
// import (
// "database/sql"
// "go-task/graph"
// "go-task/pkg/generated"
// "go-task/token"
// "go-task/util"
// "log"
// "os"
// repoAuth "go-task/internal/auths/repository/postgres"
// repoLabel "go-task/internal/labels/repository/postgres"
// repoTask "go-task/internal/tasks/repository/postgres"
// "github.com/99designs/gqlgen/graphql/handler"
// "github.com/99designs/gqlgen/graphql/playground"
// "github.com/gin-gonic/gin"
// _ "github.com/golang-migrate/migrate/v4/database/postgres"
// _ "github.com/golang-migrate/migrate/v4/source/file"
// _ "github.com/lib/pq"
// useAuth "go-task/internal/auths/usecase"
// useLabel "go-task/internal/labels/usecase"
// useTask "go-task/internal/tasks/usecase"
// )
// const defaultPort = ":8080"
// func main() {
// port := os.Getenv("PORT")
// if port == "" {
// port = defaultPort
// }
// config, err := util.LoadConfig(".")
// if err != nil {
// log.Fatalf("Cannot set config: %v", err.Error())
// }
// tokenMaker, err := token.NewJWTMaker(config.TokenSymmetricKey)
// if err != nil {
// log.Fatal(err)
// }
// r := gin.Default()
// // r.Use(middlewares.AuthMiddleware(tokenMaker, config))
// r.POST("/query", graphqlHandler(config, tokenMaker))
// r.GET("/", playgroundHandler())
// log.Printf("connect to http://localhost:%s/ for GraphQL playground", port)
// r.Run(defaultPort)
// }
// // Defining the Graphql handler
// func graphqlHandler(config util.Config, tokenMaker token.Maker) gin.HandlerFunc {
// conn, err := sql.Open(config.DBDriver, config.DBSource)
// if err != nil {
// log.Fatalf("Cannot connect to db:")
// }
// authRepo := repoAuth.NewAuthentication(conn)
// labelRepo := repoLabel.NewLabel(conn)
// taskLabel := repoTask.NewStore(conn)
// auths := useAuth.NewAuthusecase(authRepo, config, tokenMaker)
// label := useLabel.NewLabelusecase(labelRepo, config, tokenMaker)
// task := useTask.NewTaskusecase(taskLabel, config, tokenMaker)
// srv := handler.NewDefaultServer(generated.NewExecutableSchema(generated.Config{Resolvers: &graph.Resolver{Auth: auths, Label: label, Task: task}}))
// return func(c *gin.Context) {
// srv.ServeHTTP(c.Writer, c.Request)
// }
// }
// // Defining the Playground handler
// func playgroundHandler() gin.HandlerFunc {
// srv := playground.Handler("GraphQL playground", "/query")
// return func(c *gin.Context) {
// srv.ServeHTTP(c.Writer, c.Request)
// }
// }
// // db := store.NewStore()
// // srv := handler.NewDefaultServer(generated.NewExecutableSchema(generated.Config{Resolvers: &graph.Resolver{}}))
// // http.Handle("/", playground.Handler("GraphQL playground", "/query"))
// // http.Handle("/query", store.WithStore(db, srv))