-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (45 loc) · 1.11 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
package main
import (
"database/sql"
"go-htmx-dashboard/handlers"
"go-htmx-dashboard/internal/database"
"go-htmx-dashboard/util"
"log"
"os"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/template/html/v2"
"github.com/joho/godotenv"
_ "github.com/lib/pq"
)
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
db, err := sql.Open("postgres", os.Getenv("DB_URL"))
if err != nil {
log.Fatal(err)
}
defer db.Close()
handlerCfg := &handlers.HandlerConfig{
Db: database.New(db),
}
viewEngine := html.New("views", ".html")
app := fiber.New(fiber.Config{
Views: viewEngine,
ViewsLayout: "layouts/base",
})
app.Static("/css", "./dist/css")
app.Static("/js", "./dist/js")
setupRoutes(app, handlerCfg)
// go initialUserCreation(handlerCfg)
log.Fatal(app.Listen(":6969"))
}
func initialUserCreation(handlerCfg *handlers.HandlerConfig) {
user, err := util.CreateAUser(handlerCfg.Db, "[email protected]", "woow@123")
if err != nil {
log.Printf("error: coulnd't create user %v", err)
} else {
log.Printf("user created %v", user)
}
}