-
Notifications
You must be signed in to change notification settings - Fork 0
/
viridis.go
58 lines (46 loc) · 1.8 KB
/
viridis.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
package main
import (
"log"
"net/http"
"github.com/KrisjanisP/viridis/api"
"github.com/KrisjanisP/viridis/database"
"github.com/KrisjanisP/viridis/platform/authenticator"
"github.com/KrisjanisP/viridis/platform/middleware"
"github.com/KrisjanisP/viridis/platform/router"
"github.com/KrisjanisP/viridis/utils"
"github.com/KrisjanisP/viridis/web/app/callback"
"github.com/KrisjanisP/viridis/web/app/index"
"github.com/KrisjanisP/viridis/web/app/karte"
"github.com/KrisjanisP/viridis/web/app/login"
"github.com/KrisjanisP/viridis/web/app/logout"
"github.com/KrisjanisP/viridis/web/app/profile"
"github.com/joho/godotenv"
_ "github.com/mattn/go-sqlite3"
)
func main() {
dbapi, err := database.NewDB()
if err := godotenv.Load(); err != nil {
log.Panicf("Failed to load the env vars: %v", err)
}
auth, err := authenticator.New()
if err != nil {
log.Panicf("Failed to initialize the authenticator: %v", err)
}
rtr := router.New()
rtr.Static("/assets", "./web/assets") // serve html
rtr.Static("/dist", "./web/dist") // serve javascript, css
rtr.LoadHTMLGlob("web/template/*")
rtr.GET("/", index.Handler)
rtr.GET("/login", login.Handler(auth))
rtr.GET("/callback", callback.Handler(auth))
rtr.GET("/map.html", middleware.IsAuthenticated, karte.Handler)
rtr.GET("/logout", logout.Handler)
rtr.GET("/profile.html", middleware.IsAuthenticated, profile.DBAPI{DBAPI: dbapi}.Handler)
rtr.GET("/tiles", middleware.IsAuthenticated, api.DBAPI{DBAPI: dbapi}.GetTiles)
rtr.POST("/tiles", middleware.IsAuthenticated, api.DBAPI{DBAPI: dbapi}.PostTiles)
rtr.GET("/download/:tileid/:type", middleware.IsAuthenticated, api.DBAPI{DBAPI: dbapi}.DownloadFile)
go utils.StartWorker(dbapi)
if err := http.ListenAndServe(":8080", rtr); err != nil {
log.Panicf("There was an error with the http server: %v", err)
}
}