forked from gofiber/recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.go
More file actions
35 lines (26 loc) 路 639 Bytes
/
Copy pathapp.go
File metadata and controls
35 lines (26 loc) 路 639 Bytes
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
package main
import (
"log"
"gorm-mysql/database"
"gorm-mysql/routes"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
)
func setUpRoutes(app *fiber.App) {
app.Get("/hello", routes.Hello)
app.Get("/allbooks", routes.AllBooks)
app.Get("/book/:id", routes.GetBook)
app.Post("/book", routes.AddBook)
app.Put("/book/:id", routes.Update)
app.Delete("/book/:id", routes.Delete)
}
func main() {
database.ConnectDb()
app := fiber.New()
setUpRoutes(app)
app.Use(cors.New())
app.Use(func(c *fiber.Ctx) error {
return c.SendStatus(404) // => 404 "Not Found"
})
log.Fatal(app.Listen(":3000"))
}