-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
47 lines (37 loc) · 960 Bytes
/
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
package main
import (
"fmt"
gql "graphql_api/graphQL"
grapqhlconfig "graphql_api/graphQL/configuration"
"graphql_api/initialization"
"graphql_api/keys"
"graphql_api/middlewares"
"log"
"net/http"
"time"
"github.com/99designs/gqlgen/handler"
"github.com/gorilla/mux"
)
var port = fmt.Sprintf(":%s", keys.GetKeys().PORT)
var router = mux.NewRouter()
/*
Initializes environment variables and establishes
a connection to MongoDB.
*/
func init() {
initialization.InitEnv()
initialization.InitDatabase()
}
func main() {
router.Use(middlewares.VerifyJwt)
router.Handle("/playground", handler.Playground("playground", "/graphql"))
router.Handle("/graphql", handler.GraphQL(gql.NewExecutableSchema(grapqhlconfig.GetConfig())))
srv := &http.Server{
Addr: port,
Handler: router,
ReadTimeout: 10 * time.Second,
WriteTimeout: 20 * time.Second,
}
log.Println("🆙 Server listening on port", port)
srv.ListenAndServe()
}