Exemple #1
0
// Error will simply return the error to the calling request stack.
func Error(err error) web.Handler {

	// Create this really, really simple handler.
	return web.Handler(func(c *web.Context) error {
		return err
	})
}
Exemple #2
0
// Handler will serve a JSON payload as the endpoint response.
func Handler(name string, code int) web.Handler {

	// Load the fixture for response.
	var fixture interface{}
	if err := Load(name, &fixture); err != nil {
		return Error(err)
	}

	// Provide the handler which will just serve the json fixture
	// out to the client.
	return web.Handler(func(c *web.Context) error {

		// Respond with the fixture and the code.
		c.Respond(fixture, code)
		return nil
	})
}