-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
42 lines (34 loc) · 900 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
package main
import (
"database/sql"
"os"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
_ "github.com/mattn/go-sqlite3"
"github.com/microcosm-cc/bluemonday"
)
var db *sql.DB
var dbErr error
var htmlStripper *bluemonday.Policy
var notesSanitizer *bluemonday.Policy
func main() {
htmlStripper = bluemonday.StrictPolicy()
notesSanitizer = bluemonday.UGCPolicy()
err := godotenv.Load(".env")
checkErr(err)
db, dbErr = sql.Open("sqlite3", os.Getenv("DATABASE_PATH"))
checkErr(dbErr)
defer db.Close()
_, dbErr = db.Exec("PRAGMA foreign_keys = ON;")
checkErr(dbErr)
router := gin.Default()
router.Static("/logic", "frontend/logic")
router.Static("/style", "frontend/style")
router.Static("/assets", "frontend/assets")
router.LoadHTMLGlob("frontend/*.html")
setUpRoutes(router)
if os.Getenv("PORT") == "" {
router.Run(":8080")
}
router.Run(":" + os.Getenv("PORT"))
}