(next http.Handler)
| 61 | } |
| 62 | |
| 63 | func (m *Manager) Middleware(next http.Handler) http.Handler { |
| 64 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 65 | token := bearerToken(r.Header.Get("Authorization")) |
| 66 | if token == "" || !m.valid(token) { |
| 67 | writeJSON(w, http.StatusUnauthorized, map[string]any{"error": "unauthorized"}) |
| 68 | return |
| 69 | } |
| 70 | next.ServeHTTP(w, r) |
| 71 | }) |
| 72 | } |
| 73 | |
| 74 | func (m *Manager) HandleLogin(w http.ResponseWriter, r *http.Request) { |
| 75 | if r.Method != http.MethodPost { |