Skip to content

Latest commit

 

History

History
74 lines (53 loc) · 1.72 KB

README.md

File metadata and controls

74 lines (53 loc) · 1.72 KB
title keywords description
Server Timing
server timing
Adding Server Timing headers to an application.

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