Go standard library (net/http) Go
Go standard library (net/http)-এর জন্য একটি Go স্নিপেট, যা /pixel.gif-এ আসা রিকোয়েস্টের উত্তরে empty GIF পাঠায়। GIF-টি স্টার্টআপে একবারই ডিকোড হয়।
Go standard library (net/http) Go
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)