-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
48 lines (35 loc) · 918 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
48
package main
import (
"flag"
"go-go-htmx/src/helpers"
"go-go-htmx/src/router"
"log"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/template/html/v2"
)
func mainInit() {
var initDB bool
var seedDB bool
// flags declaration using flag package
flag.BoolVar(&initDB, "init-db", false, "Initialise database. Default is false")
flag.BoolVar(&seedDB, "seed-db", false, "Seed database with test data. Default is false")
flag.Parse() // after declaring flags we need to call it
if initDB {
log.Println("Initialising Database...")
helpers.InitialiseDatabase(seedDB)
}
}
func main() {
mainInit()
// Initialize standard Go html template engine
engine := html.New("./src/views", ".html")
engine.Reload(true)
// Fiber instance
app := fiber.New(fiber.Config{
Views: engine,
ViewsLayout: "layouts/main",
})
router.SetupRouter(app)
// Start server
log.Fatal(app.Listen(":3001"))
}