title | keywords | description | |
---|---|---|---|
Server Timing |
|
Adding Server Timing headers to an application. |
This project demonstrates how to implement Server-Timing headers in a Go application using the Fiber framework.
Ensure you have the following installed:
- Golang
- Fiber package
-
Clone the repository:
git clone https://github.com/gofiber/recipes.git cd recipes/server-timing
-
Install dependencies:
go get
- Start the application:
go run main.go
Here is an example of how to set up Server-Timing headers in a Fiber application:
package main
import (
"github.com/gofiber/fiber/v2"
"time"
)
func main() {
app := fiber.New()
app.Use(func(c *fiber.Ctx) error {
start := time.Now()
err := c.Next()
duration := time.Since(start)
c.Append("Server-Timing", "app;dur="+duration.String())
return err
})
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Hello, World!")
})
app.Listen(":3000")
}