emptygif
Language: English

All languages and frameworks

Echo Go

A Go snippet for Echo that answers requests for /pixel.gif with the empty GIF, decoded once at startup.

Echo Go

Install
go get github.com/labstack/echo/v5
File
main.go
Run
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)
	}
}

We ran this snippet and compared the bytes it returned.

Check it

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

Official site: Echo

More in Go