Created
December 15, 2014 15:44
-
-
Save attilaolah/af2d78dee4088cbbc95c to your computer and use it in GitHub Desktop.
Serve a 1-pixel PNG in Go
This file contains hidden or 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
// 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) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is for App Engine. To run on Heroku, change
init()
tomain()
.