Created
August 5, 2014 17:17
-
-
Save mikerudolph/a98dbf568abda7d00656 to your computer and use it in GitHub Desktop.
Go REST api serving json file used for benchmarking.
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 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