1package inthttp 2 3import ( 4 "encoding/json" 5 "net/http" 6 7 "github.com/gorilla/mux" 8 "github.com/matrix-org/dendrite/appservice/api" 9 "github.com/matrix-org/dendrite/internal/httputil" 10 "github.com/matrix-org/util" 11) 12 13// AddRoutes adds the AppServiceQueryAPI handlers to the http.ServeMux. 14func AddRoutes(a api.AppServiceQueryAPI, internalAPIMux *mux.Router) { 15 internalAPIMux.Handle( 16 AppServiceRoomAliasExistsPath, 17 httputil.MakeInternalAPI("appserviceRoomAliasExists", func(req *http.Request) util.JSONResponse { 18 var request api.RoomAliasExistsRequest 19 var response api.RoomAliasExistsResponse 20 if err := json.NewDecoder(req.Body).Decode(&request); err != nil { 21 return util.ErrorResponse(err) 22 } 23 if err := a.RoomAliasExists(req.Context(), &request, &response); err != nil { 24 return util.ErrorResponse(err) 25 } 26 return util.JSONResponse{Code: http.StatusOK, JSON: &response} 27 }), 28 ) 29 internalAPIMux.Handle( 30 AppServiceUserIDExistsPath, 31 httputil.MakeInternalAPI("appserviceUserIDExists", func(req *http.Request) util.JSONResponse { 32 var request api.UserIDExistsRequest 33 var response api.UserIDExistsResponse 34 if err := json.NewDecoder(req.Body).Decode(&request); err != nil { 35 return util.ErrorResponse(err) 36 } 37 if err := a.UserIDExists(req.Context(), &request, &response); err != nil { 38 return util.ErrorResponse(err) 39 } 40 return util.JSONResponse{Code: http.StatusOK, JSON: &response} 41 }), 42 ) 43} 44