emptygif
Harshe: Hausa

Duk harsuna da frameworks

chi Go

Snippet na Go don chi da ke amsa requests zuwa /pixel.gif da empty GIF, wanda ake decoding ɗinsa sau ɗaya lokacin farawa.

chi Go

Girkawa
go get github.com/go-chi/chi/v5
Fayil
main.go
Gudanar
go run .
package main

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

	"github.com/go-chi/chi/v5"
)

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

func main() {
	r := chi.NewRouter()
	r.Get("/pixel.gif", func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "image/gif")
		w.Header().Set("Cache-Control", "no-store")
		w.Write(gif)
	})
	log.Fatal(http.ListenAndServe(":8080", r))
}

Mun gudanar da wannan snippet kuma mun kwatanta bytes ɗin da ya mayar.

Duba shi

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

Shafin hukuma: chi

Ƙari a Go