ಎಲ್ಲಾ ಭಾಷೆಗಳು ಮತ್ತು ಫ್ರೇಮ್ವರ್ಕ್ಗಳು
Go standard library (net/http) Go
/pixel.gif ಗೆ ಬರುವ ವಿನಂತಿಗಳಿಗೆ ಖಾಲಿ GIF ನೊಂದಿಗೆ ಉತ್ತರಿಸುವ, Go standard library (net/http) ಗಾಗಿ ಒಂದು Go ಸ್ನಿಪೆಟ್; 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)