-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
40 lines (31 loc) · 923 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
package main
import (
"context"
"github.com/gofiber/fiber/v2"
"goweb/db"
"goweb/handlers/user"
"goweb/pages"
)
func main() {
// initialize a context to share data between different templ components
ctx := context.WithValue(context.Background(), "version", "v0.0.3")
app := fiber.New()
app.Static("/public", "./public/")
// shall be used once and commented afterwards,
// and maybe completed removed in production.
app.Get("/seed", func(c *fiber.Ctx) error {
err := db.Seed()
if err != nil {
c.Status(fiber.StatusInternalServerError).SendString("internal error.")
}
return c.SendString("Database has been seeded.")
})
app.Get("/", func(c *fiber.Ctx) error {
c.Set(fiber.HeaderContentType, fiber.MIMETextHTML)
pages.Index().Render(ctx, c.Response().BodyWriter())
return c.SendStatus(200)
})
app.Post("/login", user.Login)
app.Post("/register", user.Register)
app.Listen(":3000")
}