Skip to content

Instantly share code, notes, and snippets.

@mikerudolph
Created August 5, 2014 17:17
Show Gist options
  • Save mikerudolph/a98dbf568abda7d00656 to your computer and use it in GitHub Desktop.
Save mikerudolph/a98dbf568abda7d00656 to your computer and use it in GitHub Desktop.
Go REST api serving json file used for benchmarking.
package main
import (
"log"
"io/ioutil"
"net/http"
"github.com/ant0ine/go-json-rest/rest"
)
type Message struct {
Body string
}
func main() {
handler := rest.ResourceHandler{}
err := handler.SetRoutes(
&rest.Route{"GET", "/benchmark", func(w rest.ResponseWriter, req *rest.Request) {
J, err := ioutil.ReadFile("./small.json")
if err != nil { panic(err) }
w.Header().Set("Content-Type", "application/json")
w.(http.ResponseWriter).Write([]byte(string(J)))
}},
)
if err != nil {
log.Fatal(err)
}
log.Fatal(http.ListenAndServe(":3000", &handler))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment