emptygif
Language: English

All languages and frameworks

Hertz (CloudWeGo) Go

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

Hertz (CloudWeGo) Go

Install
go get github.com/cloudwego/hertz
File
main.go
Run
go run .
package main

import (
	"context"
	"encoding/base64"

	"github.com/cloudwego/hertz/pkg/app"
	"github.com/cloudwego/hertz/pkg/app/server"
	"github.com/cloudwego/hertz/pkg/protocol/consts"
)

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

func main() {
	h := server.Default(server.WithHostPorts(":8080"))
	h.GET("/pixel.gif", func(ctx context.Context, c *app.RequestContext) {
		c.Header("Cache-Control", "no-store")
		c.Data(consts.StatusOK, "image/gif", gif)
	})
	h.Spin()
}

We ran this snippet and compared the bytes it returned.

Check it

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

Official site: Hertz (CloudWeGo)

More in Go