emptygif
ભાષા: ગુજરાતી

બધી ભાષાઓ અને ફ્રેમવર્ક

Go standard library (net/http) Go

Go standard library (net/http) માટે Go સ્નિપેટ, જે /pixel.gif પરની રિક્વેસ્ટનો જવાબ empty GIF થી આપે છે. GIF સ્ટાર્ટઅપ વખતે એક જ વાર ડિકોડ થાય છે.

Go standard library (net/http) Go

ફાઇલ
main.go
ચલાવો
go run .
package main

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

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

func main() {
	// Go 1.22+ method-aware pattern; GET also answers HEAD.
	http.HandleFunc("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) // small bodies get Content-Length automatically
	})
	log.Fatal(http.ListenAndServe(":8080", nil))
}

અમે આ સ્નિપેટ ચલાવ્યો અને તેણે પરત કરેલા બાઇટની સરખામણી કરી.

ચકાસો

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

સત્તાવાર સાઇટ: Go standard library (net/http)

Go માં વધુ