mirror of
https://github.com/hoernschen/dendrite.git
synced 2024-12-27 23:48:27 +00:00
29 lines
940 B
Go
29 lines
940 B
Go
package inthttp
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
"github.com/matrix-org/dendrite/internal/httputil"
|
|
"github.com/matrix-org/dendrite/pushserver/api"
|
|
"github.com/matrix-org/util"
|
|
)
|
|
|
|
// AddRoutes adds the RoomserverInternalAPI handlers to the http.ServeMux.
|
|
// nolint: gocyclo
|
|
func AddRoutes(r api.PushserverInternalAPI, internalAPIMux *mux.Router) {
|
|
internalAPIMux.Handle(PushserverQueryExamplePath,
|
|
httputil.MakeInternalAPI("queryExample", func(req *http.Request) util.JSONResponse {
|
|
var request api.QueryExampleRequest
|
|
var response api.QueryExampleResponse
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
}
|
|
if err := r.QueryExample(req.Context(), &request, &response); err != nil {
|
|
return util.ErrorResponse(err)
|
|
}
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
}),
|
|
)
|
|
}
|