emptygif
Language: English

All languages and frameworks

Encore.go (raw endpoint) Go

A Go snippet for Encore.go (raw endpoint) that answers requests for /pixel.gif with the empty GIF, decoded once at startup.

Encore.go (raw endpoint) Go

Install
encore app create --example=hello-world
File
pixel.go
Run
encore run --port 8080
// pixel/pixel.go: a package with an //encore:api endpoint is an Encore service.
package pixel

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

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

// Raw endpoints get the plain http.ResponseWriter.
//
//encore:api public raw method=GET path=/pixel.gif
func Pixel(w http.ResponseWriter, req *http.Request) {
	w.Header().Set("Content-Type", "image/gif")
	w.Header().Set("Cache-Control", "no-store")
	w.Write(gif)
}

We ran this snippet and compared the bytes it returned.

Check it

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

Official site: Encore.go (raw endpoint)

More in Go