Ejemplo n.º 1
0
func ExampleServeMux_ServeHTTP() {
	mux.Handles(rest.Paths{
		"/user/:id": {
			"GET": func(c *rest.Context) error {
				return c.Send(rest.JSON{
					"user": c.Param("id"),
					"date": time.Now().UTC(),
				})
			},
			"POST": rest.Data("OK", "text/plain"),
		},
		"/favicon.ico": {
			"GET": rest.File("./favicon.ico"),
		},
	})
	http.ListenAndServe(":8080", mux)
}
Ejemplo n.º 2
0
func ExampleData() {
	mux.Handle("GET", "/static/", rest.Data("OK", ""))
	mux.Handle("GET", "/bin/",
		rest.Data([]byte{0x1, 0x2, 0x3, 0x4}, "application/octet-stream"))
}