AddRoutes adds the FederationInternalAPI handlers to the http.ServeMux. nolint:gocyclo
(intAPI api.FederationInternalAPI, internalAPIMux *mux.Router)
| 13 | // AddRoutes adds the FederationInternalAPI handlers to the http.ServeMux. |
| 14 | // nolint:gocyclo |
| 15 | func AddRoutes(intAPI api.FederationInternalAPI, internalAPIMux *mux.Router) { |
| 16 | internalAPIMux.Handle( |
| 17 | FederationAPIQueryJoinedHostServerNamesInRoomPath, |
| 18 | httputil.MakeInternalAPI("QueryJoinedHostServerNamesInRoom", func(req *http.Request) util.JSONResponse { |
| 19 | var request api.QueryJoinedHostServerNamesInRoomRequest |
| 20 | var response api.QueryJoinedHostServerNamesInRoomResponse |
| 21 | if err := json.NewDecoder(req.Body).Decode(&request); err != nil { |
| 22 | return util.ErrorResponse(err) |
| 23 | } |
| 24 | if err := intAPI.QueryJoinedHostServerNamesInRoom(req.Context(), &request, &response); err != nil { |
| 25 | return util.ErrorResponse(err) |
| 26 | } |
| 27 | return util.JSONResponse{Code: http.StatusOK, JSON: &response} |
| 28 | }), |
| 29 | ) |
| 30 | internalAPIMux.Handle( |
| 31 | FederationAPIPerformJoinRequestPath, |
| 32 | httputil.MakeInternalAPI("PerformJoinRequest", func(req *http.Request) util.JSONResponse { |
| 33 | var request api.PerformJoinRequest |
| 34 | var response api.PerformJoinResponse |
| 35 | if err := json.NewDecoder(req.Body).Decode(&request); err != nil { |
| 36 | return util.MessageResponse(http.StatusBadRequest, err.Error()) |
| 37 | } |
| 38 | intAPI.PerformJoin(req.Context(), &request, &response) |
| 39 | return util.JSONResponse{Code: http.StatusOK, JSON: &response} |
| 40 | }), |
| 41 | ) |
| 42 | internalAPIMux.Handle( |
| 43 | FederationAPIPerformLeaveRequestPath, |
| 44 | httputil.MakeInternalAPI("PerformLeaveRequest", func(req *http.Request) util.JSONResponse { |
| 45 | var request api.PerformLeaveRequest |
| 46 | var response api.PerformLeaveResponse |
| 47 | if err := json.NewDecoder(req.Body).Decode(&request); err != nil { |
| 48 | return util.MessageResponse(http.StatusBadRequest, err.Error()) |
| 49 | } |
| 50 | if err := intAPI.PerformLeave(req.Context(), &request, &response); err != nil { |
| 51 | return util.ErrorResponse(err) |
| 52 | } |
| 53 | return util.JSONResponse{Code: http.StatusOK, JSON: &response} |
| 54 | }), |
| 55 | ) |
| 56 | internalAPIMux.Handle( |
| 57 | FederationAPIPerformInviteRequestPath, |
| 58 | httputil.MakeInternalAPI("PerformInviteRequest", func(req *http.Request) util.JSONResponse { |
| 59 | var request api.PerformInviteRequest |
| 60 | var response api.PerformInviteResponse |
| 61 | if err := json.NewDecoder(req.Body).Decode(&request); err != nil { |
| 62 | return util.MessageResponse(http.StatusBadRequest, err.Error()) |
| 63 | } |
| 64 | if err := intAPI.PerformInvite(req.Context(), &request, &response); err != nil { |
| 65 | return util.ErrorResponse(err) |
| 66 | } |
| 67 | return util.JSONResponse{Code: http.StatusOK, JSON: &response} |
| 68 | }), |
| 69 | ) |
| 70 | internalAPIMux.Handle( |
| 71 | FederationAPIPerformDirectoryLookupRequestPath, |
| 72 | httputil.MakeInternalAPI("PerformDirectoryLookupRequest", func(req *http.Request) util.JSONResponse { |
nothing calls this directly
no test coverage detected