(next stdapi.HandlerFunc)
| 9 | ) |
| 10 | |
| 11 | func (s *Server) Authorize(next stdapi.HandlerFunc) stdapi.HandlerFunc { |
| 12 | return func(c *stdapi.Context) error { |
| 13 | switch c.Request().Method { |
| 14 | case http.MethodGet: |
| 15 | if !CanRead(c) { |
| 16 | return stdapi.Errorf(401, "you are unauthorized to access this") |
| 17 | } |
| 18 | default: |
| 19 | if !CanWrite(c) { |
| 20 | return stdapi.Errorf(401, "you are unauthorized to access this") |
| 21 | } |
| 22 | } |
| 23 | return next(c) |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | func CanRead(c *stdapi.Context) bool { |
| 28 | if d := c.Get(structs.ConvoxRoleParam); d != nil { |