Skip to content

Instantly share code, notes, and snippets.

@Contextualist
Created February 2, 2019 05:19
Show Gist options
  • Save Contextualist/1c18e8030692a033a5f4a221f8c86550 to your computer and use it in GitHub Desktop.
Save Contextualist/1c18e8030692a033a5f4a221f8c86550 to your computer and use it in GitHub Desktop.
package main
import (
"log"
"net/http"
)
func main() {
http.HandleFunc("/", Handler)
log.Fatal(http.ListenAndServe(":8000", nil))
}
package main
import (
"io"
"log"
"net/http"
)
func Handler(w http.ResponseWriter, _ *http.Request) {
response, err := http.Get("https://upload.wikimedia.org/wikipedia/commons/6/6b/Leuchtkäfer_-_Firefly.JPG")
if checkErr(err) { return }
w.Header().Set("Content-Type", "image/jpeg")
_, err = io.Copy(w, response.Body)
if checkErr(err) { return }
}
func checkErr(err error) bool {
if err != nil {
log.Println(err)
return true
}
return false
}
{
"version": 2,
"name": "binary-resp",
"builds": [
{ "src": "now.go", "use": "@now/go" }
],
"routes": [
{ "src": "/.*", "dest": "now.go" }
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment