-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (43 loc) · 1.19 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
package main
//go:generate go run github.com/a-h/templ/cmd/templ@latest generate
import (
"net/http"
"os"
"github.com/ShardulNalegave/PICT-EMS/database"
"github.com/ShardulNalegave/PICT-EMS/routes"
"github.com/ShardulNalegave/PICT-EMS/sessions"
"github.com/ShardulNalegave/PICT-EMS/tsdb"
"github.com/ShardulNalegave/PICT-EMS/utils"
"github.com/go-chi/chi/v5"
"github.com/joho/godotenv"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
const (
ADDR = ":8080"
)
func main() {
if godotenv.Load() != nil {
panic("Couldn't load .env")
}
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stdout})
if len(os.Args) < 2 {
panic("Not enough arguments provided")
}
loc := os.Args[1]
t := tsdb.ConnectToTSDB()
db := database.ConnectToDatabase()
sm := sessions.NewSessionManager()
r := chi.NewRouter()
r.Use(tsdb.TSDBMiddleware(t))
r.Use(database.DatabaseMiddleware(db))
r.Use(sessions.SessionManagerMiddleware(sm))
r.Use(utils.LocationMiddleware(loc))
r.Mount("/", routes.GetRouter())
log.Info().
Str("Addr", ADDR).
Msg("Listening...")
err := http.ListenAndServe(ADDR, r)
log.Fatal().Err(err).Msg("Server shut down")
}