本文整理汇总了Golang中github.com/twanies/weavebox-docker-example/Godeps/_workspace/src/github.com/twanies/weavebox.Context类的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: authenticate
// 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")
}
示例2: helloHandler
func helloHandler(ctx *weavebox.Context) error {
return ctx.Text(http.StatusOK, "Hellos you v25")
}
示例3: renderUserDetail
func renderUserDetail(ctx *weavebox.Context) error {
username := "anthony"
return ctx.Render("user/index.html", username)
}
示例4: renderIndex
func renderIndex(ctx *weavebox.Context) error {
return ctx.Render("index.html", nil)
}
示例5: errorHandler
// custom centralized error handling
func errorHandler(ctx *weavebox.Context, err error) {
http.Error(ctx.Response(), "Hey some error occured: "+err.Error(), http.StatusInternalServerError)
}
示例6: adminGreetingHandler
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)
}
示例7: dbContextHandler
func dbContextHandler(ctx *weavebox.Context) error {
db := datastore{"mydatabase"}
ctx.Context = newDatastoreContext(ctx.Context, &db)
return nil
}