-
-
Save GiovaniFerraroTrivelli/7d8ceecaaafe56a512008fef130d3a8e to your computer and use it in GitHub Desktop.
Output a 1x1 transparent gif pixel in Go webserver response. Please note, this is only the relevant code, does not work "out-of-the-box".
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"fmt" | |
"net/http" | |
"time" | |
) | |
const transPixel = "\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B" | |
func pixelHandler(w http.ResponseWriter, r *http.Request) { | |
// Pixel | |
w.Header().Set("Content-Type", "image/gif") | |
w.Header().Set("Last-Modified", time.Now().UTC().Format(http.TimeFormat)) | |
w.Header().Set("Expires", "Wed, 11 Nov 1998 11:11:11 GMT") | |
w.Header().Set("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0") | |
w.Header().Set("Pragma", "no-cache") | |
fmt.Fprintf(w, transPixel) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment