-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (36 loc) · 1.05 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
package main
import (
"log"
"github.com/Lamcam/api/database"
"github.com/Lamcam/api/routes"
"github.com/gofiber/fiber/v2"
)
func welcome(c *fiber.Ctx) error {
return c.SendString("Welcome to my API")
}
func setupRoutes(app *fiber.App) {
// welcome endpoint
app.Get("/api", welcome)
//User endpoint
app.Post("/api/users", routes.CreateUser)
app.Get("/api/users", routes.GetUsers)
app.Get("/api/users/:id", routes.GetUser)
app.Put("/api/users/:id", routes.UpdateUser)
app.Delete("/api/users/:id", routes.DeleteUser)
// Products endpoint
app.Post("/api/products", routes.CreateProduct)
app.Get("/api/products", routes.GetProducts)
app.Get("/api/products/:id", routes.GetProduct)
app.Put("/api/products/:id", routes.UpdateProduct)
app.Delete("/api/products/:id", routes.DeleteProduct)
// Order endpoint
app.Post("/api/orders", routes.CreateOrder)
app.Get("/api/orders", routes.GetOrders)
app.Get("/api/orders/:id", routes.GetOrder)
}
func main() {
database.ConnectDb()
app := fiber.New()
setupRoutes(app)
log.Fatal(app.Listen(":3000"))
}