mirror of
https://github.com/hoernschen/dendrite.git
synced 2024-12-27 07:28:27 +00:00
Merge pull request #2 from matrix-org/kegan/client-webserver
Add stub clientapi webserver with readers/writers packages
This commit is contained in:
commit
5b5c2091bf
3 changed files with 74 additions and 0 deletions
31
src/github.com/matrix-org/dendrite/clientapi/clientapi.go
Normal file
31
src/github.com/matrix-org/dendrite/clientapi/clientapi.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
|
||||
"github.com/matrix-org/dendrite/clientapi/readers"
|
||||
"github.com/matrix-org/dendrite/clientapi/writers"
|
||||
"github.com/matrix-org/util"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
// setup registers HTTP handlers with the given ServeMux. It also supplies the given http.Client
|
||||
// to clients which need to make outbound HTTP requests.
|
||||
func setup(mux *http.ServeMux, httpClient *http.Client) {
|
||||
mux.Handle("/metrics", prometheus.Handler())
|
||||
mux.Handle("/api/send", prometheus.InstrumentHandler("send_message", util.MakeJSONAPI(&writers.SendMessage{})))
|
||||
mux.Handle("/api/sync", prometheus.InstrumentHandler("sync", util.MakeJSONAPI(&readers.Sync{})))
|
||||
}
|
||||
|
||||
func main() {
|
||||
bindAddr := os.Getenv("BIND_ADDRESS")
|
||||
if bindAddr == "" {
|
||||
log.Panic("No BIND_ADDRESS environment variable found.")
|
||||
}
|
||||
log.Info("Starting clientapi")
|
||||
setup(http.DefaultServeMux, http.DefaultClient)
|
||||
log.Fatal(http.ListenAndServe(bindAddr, nil))
|
||||
}
|
21
src/github.com/matrix-org/dendrite/clientapi/readers/sync.go
Normal file
21
src/github.com/matrix-org/dendrite/clientapi/readers/sync.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
package readers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/matrix-org/util"
|
||||
)
|
||||
|
||||
// Sync handles HTTP requests to /sync
|
||||
type Sync struct{}
|
||||
|
||||
// OnIncomingRequest implements util.JSONRequestHandler
|
||||
func (s *Sync) OnIncomingRequest(req *http.Request) (interface{}, *util.HTTPError) {
|
||||
logger := req.Context().Value(util.CtxValueLogger).(*log.Entry)
|
||||
logger.Info("Doing stuff...")
|
||||
return nil, &util.HTTPError{
|
||||
Code: 404,
|
||||
Message: "Not implemented yet",
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package writers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/matrix-org/util"
|
||||
)
|
||||
|
||||
// SendMessage handles HTTP requests to /rooms/$room_id/send/$event_type
|
||||
type SendMessage struct {
|
||||
}
|
||||
|
||||
// OnIncomingRequest implements util.JSONRequestHandler
|
||||
func (s *SendMessage) OnIncomingRequest(req *http.Request) (interface{}, *util.HTTPError) {
|
||||
logger := req.Context().Value(util.CtxValueLogger).(*log.Entry)
|
||||
logger.Info("Doing stuff...")
|
||||
return nil, &util.HTTPError{
|
||||
Code: 404,
|
||||
Message: "Not implemented yet",
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue