This repository has been archived by the owner on Aug 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
71 lines (49 loc) · 1.57 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"agenda/db"
"agenda/exports"
"agenda/handlers"
"fmt"
"log"
"os"
"github.com/gofiber/fiber/v2"
"github.com/joho/godotenv"
)
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
PORT := os.Getenv("PORT")
exports.GetMongoClient()
fmt.Print("💽 | Connected to MongoDB!\n")
db.LogAllDates()
exports.App.Static("/", "./public")
exports.App.Get("/api", handlers.GetAllHandler)
exports.App.Get("/api/:date", handlers.GetDateHandler)
exports.App.Get("/api/appointment/:id", handlers.GetAppointmentHandler)
exports.App.Get("/api/year/:year", handlers.GetYearHandler)
exports.App.Get("/api/:year/:month", handlers.GetMonthHandler)
exports.App.Post("/api/new", handlers.PostNewDateHandler)
exports.App.Patch("/api/update", handlers.PatchDateHandler)
exports.App.Delete("/api/delete", handlers.DeleteDateHandler)
exports.App.Get("/:year-:month", handlers.GetUrlHandler)
exports.App.Get("*", func(c *fiber.Ctx) error {
return c.SendFile("./public/index.html")
})
fmt.Printf("⚡ | WebServer listening on [http://localhost%s]!\n", PORT)
log.Fatal(exports.App.Listen(PORT))
}
/////////////////////////////////////////////////////////////////////
/*exports.App.Post("/post", func(c *fiber.Ctx) error {
payload := struct {
Name string `json:"name"`
Email string `json:"email"`
}{}
if err := c.BodyParser(&payload); err != nil {
return err
}
fmt.Printf(payload.Name + ": " + payload.Email + "\n")
return c.JSON(payload)
})*/
///////////////////////////////////////////////////////////////////////