Skip to content

Instantly share code, notes, and snippets.

@attilaolah
Created December 15, 2014 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save attilaolah/af2d78dee4088cbbc95c to your computer and use it in GitHub Desktop.
Save attilaolah/af2d78dee4088cbbc95c to your computer and use it in GitHub Desktop.
Serve a 1-pixel PNG in Go
// Package pixel serves a one pixel image.
package pixel
import (
"encoding/base64"
"net/http"
)
const px = `iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGP6zwAAAgcBApocMXEAAAAASUVORK5CYII=`
func init() {
b, _ := base64.StdEncoding.DecodeString(px)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "image/png")
w.Write(b)
})
}
@attilaolah
Copy link
Author

This is for App Engine. To run on Heroku, change init() to main().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment