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