Middleware implements the middleware interface
(next http.Handler)
| 36 | |
| 37 | // Middleware implements the middleware interface |
| 38 | func (i *initRequired) Middleware(next http.Handler) http.Handler { |
| 39 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 40 | ctx := r.Context() |
| 41 | |
| 42 | if !i.store.HasAdminUser(ctx) { |
| 43 | w.Header().Add("Content-Type", "application/json") |
| 44 | w.WriteHeader(http.StatusConflict) |
| 45 | if err := json.NewEncoder(w).Encode(params.InitializationRequired); err != nil { |
| 46 | slog.With(slog.Any("error", err)).ErrorContext(ctx, "failed to encode response") |
| 47 | } |
| 48 | return |
| 49 | } |
| 50 | |
| 51 | next.ServeHTTP(w, r.WithContext(ctx)) |
| 52 | }) |
| 53 | } |
| 54 | |
| 55 | func NewUrlsRequiredMiddleware(store common.Store) (Middleware, error) { |
| 56 | return &urlsRequired{ |
nothing calls this directly
no test coverage detected