To get started with fiber in Go, first you need to install the fiber package using the command go get -u github.com/gofiber/fiber/v2
. After that, you can create a basic fiber server to serve HTTP requests.
main.go344 chars22 lines
You can run this server by running go run main.go
and then accessing http://localhost:3000
in your web browser.
Fiber also supports middleware which can be used to perform actions before or after route handlers are executed. Here's an example of a middleware that logs the time taken to handle each request:
main.go236 chars16 lines
This middleware can be added using app.Use
and will be run for every request that goes through the server.
gistlibby LogSnag