-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
48 lines (36 loc) · 1.24 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/gofiber/fiber/v2"
"github.com/konrad-marzec/fiber-api/database"
"github.com/konrad-marzec/fiber-api/models"
"github.com/konrad-marzec/fiber-api/routes"
)
func welcome(c *fiber.Ctx) error {
return c.SendString("Welcome to my awesome api")
}
func setupRoutes(app *fiber.App) {
app.Get("/api", welcome)
app.Get("/api/users", routes.GetUsers)
app.Get("/api/users/:id", routes.GetUser)
app.Post("/api/users", routes.CreateUser)
app.Put("/api/users/:id", routes.UpdateUser)
app.Delete("/api/users/:id", routes.DeleteUser)
app.Get("/api/users/:id/orders", routes.GetUserOrders)
app.Get("/api/products", routes.GetProducts)
app.Get("/api/products/:id", routes.GetProduct)
app.Post("/api/products", routes.CreateProduct)
app.Put("/api/products/:id", routes.UpdateProduct)
app.Delete("/api/products/:id", routes.DeleteProduct)
app.Get("/api/orders", routes.GetOrders)
app.Get("/api/orders/:id", routes.GetOrder)
app.Post("/api/orders", routes.CreateOrder)
app.Delete("/api/orders/:id", routes.DeleteOrder)
}
func main() {
database.ConnectDb()
database.Database.Db.AutoMigrate(&models.User{}, &models.Product{}, &models.Order{})
app := fiber.New()
setupRoutes(app)
log.Fatal(app.Listen(":8080"))
}