blob: 7880cd0a34a9739b2e58523673360b5c2c45b7eb (
plain) (
blame)
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
|
package main
import (
"database/sql"
"fmt"
)
type (
Authorizer struct {
db *sql.DB
Mode string
List []string
}
)
func (a *Authorizer) Handler() (func(c *Context) error, error) {
switch a.Mode {
case "none":
return func(_ *Context) error { return nil }, nil
case "list":
return func(c *Context) error {
for _, user := range a.List {
if user == c.User {
c.CanEdit = true
return nil
}
}
return nil
}, nil
case "all":
return func(c *Context) error { c.CanEdit = true; return nil }, nil
default:
return func(_ *Context) error { return nil }, fmt.Errorf("authorization mode '%s' is unsupported", a.Mode)
}
}
|