Skip to main content

Server Timing

Github StackBlitz

This project demonstrates how to implement Server-Timing headers in a Go application using the Fiber framework.

Prerequisites

Ensure you have the following installed:

Setup

  1. Clone the repository:

    git clone https://github.com/gofiber/recipes.git
    cd recipes/server-timing
  2. Install dependencies:

    go get

Running the Application

  1. 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")
}

References