emptygif
Wika: Filipino

Lahat ng language at framework

fasthttp Go

Isang Go snippet para sa fasthttp na sumasagot sa mga request sa /pixel.gif gamit ang empty GIF, na isang beses lang dine-decode sa startup.

fasthttp Go

I-install
go get github.com/valyala/fasthttp
File
main.go
Patakbuhin
go run .
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))
}

Pinatakbo namin ang snippet na ito at ikinumpara ang mga byte na ibinalik nito.

Suriin

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

Opisyal na site: fasthttp

Iba pa sa Go