forked from dstpierre/gosaas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
route.go
36 lines (29 loc) · 751 Bytes
/
route.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package gosaas
import (
"net/http"
"github.com/dstpierre/gosaas/model"
)
// Route represents a web handler with optional middlewares.
type Route struct {
// middleware
WithDB bool
Logger bool
EnforceRateLimit bool
AllowCrossOrigin bool
// authorization
MinimumRole model.Roles
Handler http.Handler
}
// NewError returns a new route that simply Respond with the error and status code.
func NewError(err error, statusCode int) *Route {
return &Route{
Logger: true,
MinimumRole: model.RolePublic,
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Respond(w, r, statusCode, err)
}),
}
}
func notFound(w http.ResponseWriter) {
http.Error(w, "not found", http.StatusNotFound)
}