本文整理匯總了Golang中github.com/flynn/flynn/Godeps/_workspace/src/github.com/martini-contrib/render.Render類的典型用法代碼示例。如果您正苦於以下問題:Golang Render類的具體用法?Golang Render怎麽用?Golang Render使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Render類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: createRoute
func createRoute(req *http.Request, route router.Route, router *Router, r render.Render) {
l := listenerFor(router, route.Type)
if l == nil {
r.JSON(400, "Invalid route type")
return
}
err := l.AddRoute(&route)
if err != nil {
if err == ErrConflict {
rjson, err := json.Marshal(&route)
if err != nil {
log.Println(err)
r.JSON(500, "unknown error")
return
}
r.JSON(409, httphelper.JSONError{
Code: httphelper.ConflictErrorCode,
Message: "Duplicate route",
Detail: rjson,
})
return
}
log.Println(err)
r.JSON(500, "unknown error")
return
}
r.JSON(200, route)
}
示例2: getRoutes
func getRoutes(req *http.Request, rtr *Router, r render.Render) {
routes, err := rtr.HTTP.List()
if err != nil {
log.Println(err)
r.JSON(500, struct{}{})
return
}
tcpRoutes, err := rtr.TCP.List()
if err != nil {
log.Println(err)
r.JSON(500, struct{}{})
return
}
routes = append(routes, tcpRoutes...)
if ref := req.URL.Query().Get("parent_ref"); ref != "" {
filtered := make([]*router.Route, 0)
for _, route := range routes {
if route.ParentRef == ref {
filtered = append(filtered, route)
}
}
routes = filtered
}
for i, route := range routes {
routes[i] = formatRoute(route)
}
sort.Sort(sortedRoutes(routes))
r.JSON(200, routes)
}
示例3: createDatabase
func createDatabase(db *postgres.DB, r render.Render) {
username, password, database := random.Hex(16), random.Hex(16), random.Hex(16)
if _, err := db.Exec(fmt.Sprintf(`CREATE USER "%s" WITH PASSWORD '%s'`, username, password)); err != nil {
log.Println(err)
r.JSON(500, struct{}{})
return
}
if _, err := db.Exec(fmt.Sprintf(`CREATE DATABASE "%s" WITH OWNER = "%s"`, database, username)); err != nil {
db.Exec(fmt.Sprintf(`DROP USER "%s"`, username))
log.Println(err)
r.JSON(500, struct{}{})
return
}
r.JSON(200, &resource{
ID: fmt.Sprintf("/databases/%s:%s", username, database),
Env: map[string]string{
"FLYNN_POSTGRES": serviceName,
"PGUSER": username,
"PGPASSWORD": password,
"PGDATABASE": database,
},
})
}
示例4: deleteRoute
func deleteRoute(params martini.Params, router *Router, r render.Render) {
l := listenerFor(router, params["route_type"])
if l == nil {
r.JSON(404, struct{}{})
return
}
err := l.RemoveRoute(params["route_id"])
if err == ErrNotFound {
r.JSON(404, struct{}{})
return
}
if err != nil {
log.Println(err)
r.JSON(500, struct{}{})
return
}
r.JSON(200, struct{}{})
}
示例5: getRoute
func getRoute(params martini.Params, router *Router, r render.Render) {
l := listenerFor(router, params["route_type"])
if l == nil {
r.JSON(404, "not found")
return
}
route, err := l.Get(params["id"])
if err == ErrNotFound {
r.JSON(404, "not found")
return
}
if err != nil {
log.Println(err)
r.JSON(500, "unknown error")
return
}
r.JSON(200, route)
}
示例6: updateRoute
func updateRoute(params martini.Params, route router.Route, router *Router, r render.Render) {
route.Type = params["route_type"]
route.ID = params["id"]
l := listenerFor(router, route.Type)
if l == nil {
r.JSON(400, "Invalid route type")
return
}
if err := l.UpdateRoute(&route); err != nil {
if err == ErrNotFound {
r.JSON(404, "not found")
return
}
log.Println(err)
r.JSON(500, "unknown error")
return
}
r.JSON(200, route)
}
示例7: createRoute
func createRoute(req *http.Request, route router.Route, router *Router, r render.Render) {
l := listenerFor(router, route.Type)
if l == nil {
r.JSON(400, "Invalid route type")
return
}
if err := l.AddRoute(&route); err != nil {
log.Println(err)
r.JSON(500, "unknown error")
return
}
r.JSON(200, route)
}
示例8: createOrReplaceRoute
func createOrReplaceRoute(req *http.Request, route router.Route, router *Router, r render.Render) {
now := time.Now()
route.CreatedAt = &now
route.UpdatedAt = &now
l := listenerFor(router, route.Type)
if l == nil {
r.JSON(400, "Invalid route type")
return
}
if err := l.SetRoute(&route); err != nil {
log.Println(err)
r.JSON(500, struct{}{})
return
}
res := formatRoute(&route)
r.JSON(200, res)
}