emptygif
Langue: Français

Tous les langages et frameworks

Echo Go

Un extrait Go pour Echo qui répond aux requêtes sur /pixel.gif avec le GIF vide, décodé une seule fois au démarrage.

Echo Go

Installer
go get github.com/labstack/echo/v5
Fichier
main.go
Lancer
go run .
package main

import (
	"encoding/base64"
	"log"
	"net/http"

	"github.com/labstack/echo/v5"
)

var gif, _ = base64.StdEncoding.DecodeString("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")

func main() {
	e := echo.New()
	e.GET("/pixel.gif", func(c *echo.Context) error {
		c.Response().Header().Set("Cache-Control", "no-store")
		return c.Blob(http.StatusOK, "image/gif", gif)
	})
	if err := e.Start(":8080"); err != nil {
		log.Fatal(err)
	}
}

Nous avons exécuté cet extrait et comparé les octets qu’il a renvoyés.

Vérifier

curl -sI http://localhost:8080/pixel.gif

Site officiel: Echo

Autres extraits en Go