This repository has been archived by the owner on Jan 6, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
69 lines (58 loc) · 1.89 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
package main
import (
"github.com/go-chi/chi/v5"
"github.com/joho/godotenv"
"github.com/sirupsen/logrus"
"log"
"net/http"
"nino.sh/api/graphql"
"nino.sh/api/managers"
"nino.sh/api/metrics"
"nino.sh/api/redis"
"nino.sh/api/routers"
"nino.sh/api/utils"
"os"
)
var version = "0.2.0"
func init() {
logrus.SetFormatter(&logrus.TextFormatter{})
err := godotenv.Load(".env"); if err != nil {
panic(err)
}
utils.ValidateEnv()
logrus.Infof("Running v%s of Nino API", version)
}
func main() {
node := os.Getenv("REGION"); if node != "" {
logrus.Infof("Running on node %s. :3", node)
}
logrus.WithField("bootstrap", "Postgres").Info("Connecting to PostgreSQL...")
postgres := managers.NewPostgresManager()
if err := postgres.GetConnection(); err != nil {
logrus.WithField("bootstrap", "Postgres").Fatalf("Unable to connect to Postgres: %v", err)
os.Exit(1)
}
logrus.WithField("bootstrap", "Redis").Info("Connecting to Redis...")
r := redis.NewRedisClient()
if err := r.Connect(); err != nil {
logrus.WithField("bootstrap", "Redis").Fatalf("Unable to connect to Redis: %v", err)
os.Exit(1)
}
logrus.WithField("bootstrap", "Redis").Info("Connected to Redis! :3")
logrus.WithField("bootstrap", "GraphQL").Info("Creating GraphQL server...")
gql := graphql.NewGraphQLManager(postgres, r)
if err := gql.GenerateSchema(); err != nil {
panic(err)
}
logrus.WithField("bootstrap", "Metrics").Info("Registering Metrics handler...")
m := metrics.NewMetrics()
m.Register()
router := chi.NewRouter()
router.Mount("/", routers.NewMainRouter())
router.Mount("/metrics", routers.NewMetricsRouter(m))
router.Mount("/health", routers.NewHealthRouter())
router.Mount("/graphql", routers.NewGraphQLRouter(gql))
router.Mount("/web-vitals", routers.NewWebVitalsRouter(m))
logrus.WithField("bootstrap", "Http").Info("Listening at http://localhost:6645!")
log.Fatal(http.ListenAndServe(":6645", router))
}