Skip to content

Commit

Permalink
Add a Forbidden() Result
Browse files Browse the repository at this point in the history
  • Loading branch information
robfig committed Feb 17, 2013
1 parent e47b74e commit c09912d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
12 changes: 12 additions & 0 deletions controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,18 @@ func (c *Controller) NotFound(msg string, objs ...interface{}) Result {
})
}

func (c *Controller) Forbidden(msg string, objs ...interface{}) Result {
finalText := msg
if len(objs) > 0 {
finalText = fmt.Sprintf(msg, objs...)
}
c.Response.Status = http.StatusForbidden
return c.RenderError(&Error{
Title: "Forbidden",
Description: finalText,
})
}

// Return a file, either displayed inline or downloaded as an attachment.
// The name and size are taken from the file info.
func (c *Controller) RenderFile(file *os.File, delivery ContentDisposition) Result {
Expand Down
16 changes: 16 additions & 0 deletions templates/errors/403.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Forbidden</title>
</head>
<body>
{{with .Error}}
<h1>
{{.Title}}
</h1>
<p>
{{.Description}}
</p>
{{end}}
</body>
</html>
4 changes: 4 additions & 0 deletions templates/errors/403.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
title: "{{js .Error.Title}}",
description: "{{js .Error.Description}}"
}
3 changes: 3 additions & 0 deletions templates/errors/403.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{.Error.Title}}

{{.Error.Description}}
1 change: 1 addition & 0 deletions templates/errors/403.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<forbidden>{{.Error.Description}}</forbidden>

0 comments on commit c09912d

Please sign in to comment.