Skip to content

Commit

Permalink
restful-go/fiber: add example from july workshop
Browse files Browse the repository at this point in the history
Signed-off-by: soypete <[email protected]>
  • Loading branch information
Soypete committed Sep 13, 2023
1 parent 3ef246e commit 931397a
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions restful-go/ex-2-fiber/fiber.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"github.com/gofiber/fiber/v2"
)

func main() {
app := fiber.New()

app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Hello, World 👋!")
})
app.Route("/3weeks-go", func(api fiber.Router) {
api.Get("/testGet", func(c *fiber.Ctx) error {
return c.SendString("Hello, World!")
}).Name("foo") // /test/foo (name: test.foo)
api.Post("/testPost", func(c *fiber.Ctx) error {
body := c.Body()
if len(body) == 0 {
return c.SendStatus(fiber.StatusBadRequest)
}
return c.SendString(string(body))
}).Name("bar") // /test/bar (name: test.bar)
}, "test.")

app.Listen(":3000")
}

0 comments on commit 931397a

Please sign in to comment.