Server Timing
This project demonstrates how to implement Server-Timing headers in a Go application using the Fiber framework.
Prerequisites
Ensure you have the following installed:
- Golang
- Fiber package
Setup
-
Clone the repository:
git clone https://github.com/gofiber/recipes.git
cd recipes/server-timing -
Install dependencies:
go get
Running the Application
- Start the application:
go run main.go
Example
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")
}