Create a gist now

Instantly share code, notes, and snippets.

@aruiz /go-test.go
Last active Jan 4, 2016

package main
import (
"log"
"net/http"
"io/ioutil"
)
type MyHandler struct {
payload []byte
}
func (hdlr MyHandler) ServeHTTP (w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "text/json")
w.Write (hdlr.payload)
}
func main() {
b, err := ioutil.ReadFile("test.json")
if err != nil { panic(err) }
hdlr := MyHandler{}
hdlr.payload = b
log.Printf("Listening http://0.0.0.0:8080/")
err = http.ListenAndServe("0.0.0.0:8080", hdlr)
if err != nil { log.Fatal(err) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment