package handler import ( "encoding/json" "net/http" "git.g3e.fr/H6N/account/internal/auth" ) func writeJSON(w http.ResponseWriter, status int, v any) { w.Header().Set("Content-Type", "application/json") w.WriteHeader(status) json.NewEncoder(w).Encode(v) } func writeError(w http.ResponseWriter, status int, msg string) { writeJSON(w, status, map[string]string{"error": msg}) } // requireOwner extrait l'owner du contexte ou écrit 401 et retourne false. func requireOwner(w http.ResponseWriter, r *http.Request) (int32, bool) { id, ok := auth.OwnerFromContext(r.Context()) if !ok { writeError(w, http.StatusUnauthorized, "missing owner") return 0, false } return id, true }