mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-08-02 22:22:46 +00:00
Add push server component template
This commit is contained in:
parent
092edee210
commit
6843c3beee
22 changed files with 487 additions and 0 deletions
48
pushserver/inthttp/client.go
Normal file
48
pushserver/inthttp/client.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
package inthttp
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal/httputil"
|
||||
"github.com/matrix-org/dendrite/pushserver/api"
|
||||
"github.com/opentracing/opentracing-go"
|
||||
)
|
||||
|
||||
type httpPushserverInternalAPI struct {
|
||||
roomserverURL string
|
||||
httpClient *http.Client
|
||||
}
|
||||
|
||||
const (
|
||||
PushserverQueryExamplePath = "/pushserver/queryExample"
|
||||
)
|
||||
|
||||
// NewRoomserverClient creates a PushserverInternalAPI implemented by talking to a HTTP POST API.
|
||||
// If httpClient is nil an error is returned
|
||||
func NewPushserverClient(
|
||||
pushserverURL string,
|
||||
httpClient *http.Client,
|
||||
) (api.PushserverInternalAPI, error) {
|
||||
if httpClient == nil {
|
||||
return nil, errors.New("NewPushserverClient: httpClient is <nil>")
|
||||
}
|
||||
return &httpPushserverInternalAPI{
|
||||
roomserverURL: pushserverURL,
|
||||
httpClient: httpClient,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// SetRoomAlias implements RoomserverAliasAPI
|
||||
func (h *httpPushserverInternalAPI) QueryExample(
|
||||
ctx context.Context,
|
||||
request *api.QueryExampleRequest,
|
||||
response *api.QueryExampleResponse,
|
||||
) error {
|
||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryExample")
|
||||
defer span.Finish()
|
||||
|
||||
apiURL := h.roomserverURL + PushserverQueryExamplePath
|
||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
}
|
29
pushserver/inthttp/server.go
Normal file
29
pushserver/inthttp/server.go
Normal file
|
@ -0,0 +1,29 @@
|
|||
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}
|
||||
}),
|
||||
)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue