mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-29 12:42:46 +00:00
Add a query API to the roomserver for getting the latest events in a room. (#23)
* Start implementing a query API for go using net/rpc * Use a conventional JSON POST API rather than go net/rpc net/rpc doesn't automatically handle reconnecting and we have better logging and metrics infrastructure for monitoring HTTP apis. * Implement the query API and add it to the integration tests * Increase the timeout, travis seems to be a bit slow * Clarify that state events are the things that are not returned if they are not requested * Add utility function for converting arrays of numeric event IDs to pq Int64Arrays * Warn people against requesting empty state keys by accident
This commit is contained in:
parent
37e0b6c4c6
commit
9a8a8aedcb
12 changed files with 333 additions and 39 deletions
4
vendor/manifest
vendored
4
vendor/manifest
vendored
|
@ -98,7 +98,7 @@
|
|||
{
|
||||
"importpath": "github.com/matrix-org/util",
|
||||
"repository": "https://github.com/matrix-org/util",
|
||||
"revision": "ccef6dc7c24a7c896d96b433a9107b7c47ecf828",
|
||||
"revision": "28bd7491c8aafbf346ca23821664f0f9911ef52b",
|
||||
"branch": "master"
|
||||
},
|
||||
{
|
||||
|
@ -206,4 +206,4 @@
|
|||
"branch": "master"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
|
@ -25,11 +25,13 @@ func GetRequestID(ctx context.Context) string {
|
|||
// ctxValueLogger is the key to extract the logrus Logger.
|
||||
const ctxValueLogger = contextKeys("logger")
|
||||
|
||||
// GetLogger retrieves the logrus logger from the supplied context. Returns nil if there is no logger.
|
||||
// GetLogger retrieves the logrus logger from the supplied context. Always returns a logger,
|
||||
// even if there wasn't one originally supplied.
|
||||
func GetLogger(ctx context.Context) *log.Entry {
|
||||
l := ctx.Value(ctxValueLogger)
|
||||
if l == nil {
|
||||
return nil
|
||||
// Always return a logger so callers don't need to constantly nil check.
|
||||
return log.WithField("context", "missing")
|
||||
}
|
||||
return l.(*log.Entry)
|
||||
}
|
||||
|
|
15
vendor/src/github.com/matrix-org/util/json.go
vendored
15
vendor/src/github.com/matrix-org/util/json.go
vendored
|
@ -58,6 +58,21 @@ type JSONRequestHandler interface {
|
|||
OnIncomingRequest(req *http.Request) JSONResponse
|
||||
}
|
||||
|
||||
// jsonRequestHandlerWrapper is a wrapper to allow in-line functions to conform to util.JSONRequestHandler
|
||||
type jsonRequestHandlerWrapper struct {
|
||||
function func(req *http.Request) JSONResponse
|
||||
}
|
||||
|
||||
// OnIncomingRequest implements util.JSONRequestHandler
|
||||
func (r *jsonRequestHandlerWrapper) OnIncomingRequest(req *http.Request) JSONResponse {
|
||||
return r.function(req)
|
||||
}
|
||||
|
||||
// NewJSONRequestHandler converts the given OnIncomingRequest function into a JSONRequestHandler
|
||||
func NewJSONRequestHandler(f func(req *http.Request) JSONResponse) JSONRequestHandler {
|
||||
return &jsonRequestHandlerWrapper{f}
|
||||
}
|
||||
|
||||
// Protect panicking HTTP requests from taking down the entire process, and log them using
|
||||
// the correct logger, returning a 500 with a JSON response rather than abruptly closing the
|
||||
// connection. The http.Request MUST have a ctxValueLogger.
|
||||
|
|
|
@ -164,8 +164,8 @@ func TestGetLogger(t *testing.T) {
|
|||
|
||||
noLoggerInReq, _ := http.NewRequest("GET", "http://example.com/foo", nil)
|
||||
ctxLogger = GetLogger(noLoggerInReq.Context())
|
||||
if ctxLogger != nil {
|
||||
t.Errorf("TestGetLogger wanted nil logger, got '%v'", ctxLogger)
|
||||
if ctxLogger == nil {
|
||||
t.Errorf("TestGetLogger wanted logger, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue