Exemplo n.º 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")
}
Exemplo n.º 2
0
func helloHandler(ctx *weavebox.Context) error {
	return ctx.Text(http.StatusOK, "Hellos you v25")
}
Exemplo n.º 3
0
func renderUserDetail(ctx *weavebox.Context) error {
	username := "******"
	return ctx.Render("user/index.html", username)
}
Exemplo n.º 4
0
func renderIndex(ctx *weavebox.Context) error {
	return ctx.Render("index.html", nil)
}
Exemplo n.º 5
0
// custom centralized error handling
func errorHandler(ctx *weavebox.Context, err error) {
	http.Error(ctx.Response(), "Hey some error occured: "+err.Error(), http.StatusInternalServerError)
}
Exemplo n.º 6
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)
}
Exemplo n.º 7
0
func dbContextHandler(ctx *weavebox.Context) error {
	db := datastore{"mydatabase"}
	ctx.Context = newDatastoreContext(ctx.Context, &db)
	return nil
}