Example #1
0
// Only the powerfull have access to the admin routes
func authenticate(ctx *weavebox.Context) error {
	admins := []string{"toby", "master iy", "c.froome"}
	name := ctx.Param("name")

	for _, admin := range admins {
		if admin == name {
			return nil
		}
	}
	return errors.New("access forbidden")
}
Example #2
0
func renderUserDetail(ctx *weavebox.Context) error {
	username := "******"
	return ctx.Render("user/index.html", username)
}
Example #3
0
func renderIndex(ctx *weavebox.Context) error {
	return ctx.Render("index.html", nil)
}
Example #4
0
// custom centralized error handling
func errorHandler(ctx *weavebox.Context, err error) {
	http.Error(ctx.Response(), "Hey some error occured: "+err.Error(), http.StatusInternalServerError)
}
Example #5
0
func adminGreetingHandler(ctx *weavebox.Context) error {
	name := ctx.Param("name")
	db := datastoreFromContext(ctx.Context)
	greeting := fmt.Sprintf("Greetings powerfull admin, %s\nYour database %s is ready", name, db.name)
	return ctx.Text(http.StatusOK, greeting)
}
Example #6
0
func dbContextHandler(ctx *weavebox.Context) error {
	db := datastore{"mydatabase"}
	ctx.Context = newDatastoreContext(ctx.Context, &db)
	return nil
}