Skip to content

Instantly share code, notes, and snippets.

@RobinUS2
Created November 25, 2013 11:23
Show Gist options
  • Save RobinUS2/7639902 to your computer and use it in GitHub Desktop.
Save RobinUS2/7639902 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".
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