dendrite/pushserver/inthttp/server.go

30 lines
940 B
Go
Raw Permalink Normal View History

2021-05-05 10:45:28 +00:00
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}
}),
)
}