Exemplo n.º 1
0
func BenchmarkGet(b *testing.B) {
	router := httprouter.New()
	router.GET("/hello/:name", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {})

	for i := 0; i < b.N; i++ {
		r, err := http.NewRequest("GET", "/hello/foo", nil)
		if err != nil {
			panic(err)
		}
		w := httptest.NewRecorder()
		router.ServeHTTP(w, r)
	}

}
Exemplo n.º 2
0
func main() {
	//instantiate location controller(mongo session) and httprouter
	hr := httprouter.New()
	loc := controllers.NewLocationController(getSession())

	// Get(read) a location resource
	hr.GET("/locations/:location_id", loc.GetLocation)

	// Create a new address
	hr.POST("/locations", loc.CreateLocation)

	// Update an existinf address
	hr.PUT("/locations/:location_id", loc.UpdateLocation)

	// Remove an existing address
	hr.DELETE("/locations/:location_id", loc.RemoveLocation)

	// start server
	http.ListenAndServe("localhost:8080", hr)
}