mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-10-09 19:22:47 +00:00
Convert everything but serverkeyapi to inthttp (#1096)
* Convert roomserver to new inthttp format * Convert eduserver to new inthttp format * Convert appservice to new inthttp format
This commit is contained in:
parent
d785ad82b9
commit
9834ac97db
29 changed files with 879 additions and 1013 deletions
56
eduserver/inthttp/client.go
Normal file
56
eduserver/inthttp/client.go
Normal file
|
@ -0,0 +1,56 @@
|
|||
package inthttp
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/matrix-org/dendrite/eduserver/api"
|
||||
internalHTTP "github.com/matrix-org/dendrite/internal/http"
|
||||
"github.com/opentracing/opentracing-go"
|
||||
)
|
||||
|
||||
// HTTP paths for the internal HTTP APIs
|
||||
const (
|
||||
EDUServerInputTypingEventPath = "/eduserver/input"
|
||||
EDUServerInputSendToDeviceEventPath = "/eduserver/sendToDevice"
|
||||
)
|
||||
|
||||
// NewEDUServerClient creates a EDUServerInputAPI implemented by talking to a HTTP POST API.
|
||||
func NewEDUServerClient(eduServerURL string, httpClient *http.Client) (api.EDUServerInputAPI, error) {
|
||||
if httpClient == nil {
|
||||
return nil, errors.New("NewEDUServerClient: httpClient is <nil>")
|
||||
}
|
||||
return &httpEDUServerInputAPI{eduServerURL, httpClient}, nil
|
||||
}
|
||||
|
||||
type httpEDUServerInputAPI struct {
|
||||
eduServerURL string
|
||||
httpClient *http.Client
|
||||
}
|
||||
|
||||
// InputTypingEvent implements EDUServerInputAPI
|
||||
func (h *httpEDUServerInputAPI) InputTypingEvent(
|
||||
ctx context.Context,
|
||||
request *api.InputTypingEventRequest,
|
||||
response *api.InputTypingEventResponse,
|
||||
) error {
|
||||
span, ctx := opentracing.StartSpanFromContext(ctx, "InputTypingEvent")
|
||||
defer span.Finish()
|
||||
|
||||
apiURL := h.eduServerURL + EDUServerInputTypingEventPath
|
||||
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
}
|
||||
|
||||
// InputSendToDeviceEvent implements EDUServerInputAPI
|
||||
func (h *httpEDUServerInputAPI) InputSendToDeviceEvent(
|
||||
ctx context.Context,
|
||||
request *api.InputSendToDeviceEventRequest,
|
||||
response *api.InputSendToDeviceEventResponse,
|
||||
) error {
|
||||
span, ctx := opentracing.StartSpanFromContext(ctx, "InputSendToDeviceEvent")
|
||||
defer span.Finish()
|
||||
|
||||
apiURL := h.eduServerURL + EDUServerInputSendToDeviceEventPath
|
||||
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
}
|
41
eduserver/inthttp/server.go
Normal file
41
eduserver/inthttp/server.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package inthttp
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/matrix-org/dendrite/eduserver/api"
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/util"
|
||||
)
|
||||
|
||||
// AddRoutes adds the EDUServerInputAPI handlers to the http.ServeMux.
|
||||
func AddRoutes(t api.EDUServerInputAPI, internalAPIMux *mux.Router) {
|
||||
internalAPIMux.Handle(EDUServerInputTypingEventPath,
|
||||
internal.MakeInternalAPI("inputTypingEvents", func(req *http.Request) util.JSONResponse {
|
||||
var request api.InputTypingEventRequest
|
||||
var response api.InputTypingEventResponse
|
||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
||||
}
|
||||
if err := t.InputTypingEvent(req.Context(), &request, &response); err != nil {
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
||||
}),
|
||||
)
|
||||
internalAPIMux.Handle(EDUServerInputSendToDeviceEventPath,
|
||||
internal.MakeInternalAPI("inputSendToDeviceEvents", func(req *http.Request) util.JSONResponse {
|
||||
var request api.InputSendToDeviceEventRequest
|
||||
var response api.InputSendToDeviceEventResponse
|
||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
||||
}
|
||||
if err := t.InputSendToDeviceEvent(req.Context(), &request, &response); err != nil {
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
||||
}),
|
||||
)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue