emptygif
Idioma: Español

Todos los lenguajes y frameworks

Encore.go (raw endpoint) Go

Un fragmento en Go para Encore.go (raw endpoint) que responde a las peticiones a /pixel.gif con el GIF vacío, decodificado una sola vez al arrancar.

Encore.go (raw endpoint) Go

Instalar
encore app create --example=hello-world
Archivo
pixel.go
Ejecutar
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)
}

Ejecutamos este fragmento y comparamos los bytes que devolvió.

Comprobar

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

Sitio oficial: Encore.go (raw endpoint)

Más en Go