emptygif
Language: English

All languages and frameworks

Gin Go

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

Gin Go

Install
go get github.com/gin-gonic/gin
File
main.go
Run
go run .
package main

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

	"github.com/gin-gonic/gin"
)

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

func main() {
	r := gin.Default()
	r.GET("/pixel.gif", func(c *gin.Context) {
		c.Header("Cache-Control", "no-store")
		c.Data(http.StatusOK, "image/gif", gif)
	})
	r.Run(":8080")
}

We ran this snippet and compared the bytes it returned.

Check it

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

Official site: Gin

More in Go