fasthttp Go
Snippet Go kanggo fasthttp sing mangsuli request menyang /pixel.gif nganggo empty GIF, sing didekode sepisan nalika startup.
fasthttp Go
package main
import (
"encoding/base64"
"log"
"github.com/valyala/fasthttp"
)
var gif, _ = base64.StdEncoding.DecodeString("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")
func handler(ctx *fasthttp.RequestCtx) {
if !ctx.IsGet() || string(ctx.Path()) != "/pixel.gif" {
ctx.NotFound()
return
}
ctx.SetContentType("image/gif")
ctx.Response.Header.Set("Cache-Control", "no-store")
ctx.SetBody(gif)
}
func main() {
log.Fatal(fasthttp.ListenAndServe(":8080", handler))
}
Snippet iki wis dilakokake lan byte asile wis dibandhingake.
Priksa
curl -sI http://localhost:8080/pixel.gif