diff --git a/src/github.com/matrix-org/dendrite/clientapi/clientapi.go b/src/github.com/matrix-org/dendrite/clientapi/clientapi.go new file mode 100644 index 00000000..1e83a43a --- /dev/null +++ b/src/github.com/matrix-org/dendrite/clientapi/clientapi.go @@ -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("/send", prometheus.InstrumentHandler("send_message", util.MakeJSONAPI(&writers.SendMessage{}))) + mux.Handle("/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)) +} diff --git a/src/github.com/matrix-org/dendrite/clientapi/readers/sync.go b/src/github.com/matrix-org/dendrite/clientapi/readers/sync.go new file mode 100644 index 00000000..fcec593a --- /dev/null +++ b/src/github.com/matrix-org/dendrite/clientapi/readers/sync.go @@ -0,0 +1,19 @@ +package readers + +import ( + "net/http" + + log "github.com/Sirupsen/logrus" + "github.com/matrix-org/util" +) + +type Sync struct{} + +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", + } +} diff --git a/src/github.com/matrix-org/dendrite/clientapi/writers/sendmessage.go b/src/github.com/matrix-org/dendrite/clientapi/writers/sendmessage.go new file mode 100644 index 00000000..55cab225 --- /dev/null +++ b/src/github.com/matrix-org/dendrite/clientapi/writers/sendmessage.go @@ -0,0 +1,20 @@ +package writers + +import ( + "net/http" + + log "github.com/Sirupsen/logrus" + "github.com/matrix-org/util" +) + +type SendMessage struct { +} + +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", + } +}