-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.go
48 lines (35 loc) · 1.66 KB
/
handler.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
37
38
39
40
41
42
43
44
45
46
47
48
package enliven
// NextHandlerFunc allow use of ordinary functions middleware handlers
// Copied w/ alterations from github.com/codegangsta/negroni
type NextHandlerFunc func(*Context)
// Copied w/ alterations from github.com/codegangsta/negroni
func (nh NextHandlerFunc) ServeHTTP(ctx *Context) {
nh(ctx)
}
// --------------------------------------------------
// HandlerFunc allow use of ordinary functions middleware handlers
// Copied w/ alterations from github.com/codegangsta/negroni
type HandlerFunc func(*Context, NextHandlerFunc)
// Copied w/ alterations from github.com/codegangsta/negroni
func (h HandlerFunc) ServeHTTP(ctx *Context, next NextHandlerFunc) {
h(ctx, next)
}
// Initialize initializes this function middleware by doing nothing
func (h HandlerFunc) Initialize(ev *Enliven) {}
// GetName returns an empty string for this function middleware
func (h HandlerFunc) GetName() string {
return ""
}
// --------------------------------------------------
// RouteHandlerFunc is an interface to be used when writing route handler functions
type RouteHandlerFunc func(*Context)
// --------------------------------------------------
// DefaultAuth is a simple implementation of IAuthorizer to stand in for auth checking/adding
// This should be overridden by the user app or something else if permissions checking is needed.
type DefaultAuth struct{}
// HasPermission is the default permission checker and always returns true
func (da *DefaultAuth) HasPermission(permission string, ctx *Context) bool {
return true
}
// AddPermission is the default permission adder, and does nothing.
func (da *DefaultAuth) AddPermission(permission string, ev *Enliven, groups ...string) {}