Esempio n. 1
0
func gearHeaderExample(c context.Context, w http.ResponseWriter, r *http.Request) context.Context {

	var err error

	// something happened
	// err = fmt.Errorf("Something bad happened") // uncomment to see how errors are returned

	if err != nil {
		// something didn't work out..
		errCtx := gears.NewErrorContext(c, gears.NewStatusError(http.StatusInternalServerError, "Sorry, just can't..."))
		return errCtx
	}

	// otherwise do your thing
	w.Header().Set("Content-Type", "application/json")
	return c
}
Esempio n. 2
0
func gearErrorExample(c context.Context, w http.ResponseWriter, r *http.Request) context.Context {

	// let's say we have an error here
	err := fmt.Errorf("Can't do that, sorry... would you like a hot beverage?")
	return gears.NewErrorContext(c, gears.NewStatusError(http.StatusInternalServerError, err.Error()))
}