This repository was archived by the owner on Nov 25, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +74
-0
lines changed
src/github.com/matrix-org/dendrite/clientapi Expand file tree Collapse file tree 3 files changed +74
-0
lines changed Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "net/http"
5+ "os"
6+
7+ log "github.com/Sirupsen/logrus"
8+
9+ "github.com/matrix-org/dendrite/clientapi/readers"
10+ "github.com/matrix-org/dendrite/clientapi/writers"
11+ "github.com/matrix-org/util"
12+ "github.com/prometheus/client_golang/prometheus"
13+ )
14+
15+ // setup registers HTTP handlers with the given ServeMux. It also supplies the given http.Client
16+ // to clients which need to make outbound HTTP requests.
17+ func setup (mux * http.ServeMux , httpClient * http.Client ) {
18+ mux .Handle ("/metrics" , prometheus .Handler ())
19+ mux .Handle ("/api/send" , prometheus .InstrumentHandler ("send_message" , util .MakeJSONAPI (& writers.SendMessage {})))
20+ mux .Handle ("/api/sync" , prometheus .InstrumentHandler ("sync" , util .MakeJSONAPI (& readers.Sync {})))
21+ }
22+
23+ func main () {
24+ bindAddr := os .Getenv ("BIND_ADDRESS" )
25+ if bindAddr == "" {
26+ log .Panic ("No BIND_ADDRESS environment variable found." )
27+ }
28+ log .Info ("Starting clientapi" )
29+ setup (http .DefaultServeMux , http .DefaultClient )
30+ log .Fatal (http .ListenAndServe (bindAddr , nil ))
31+ }
Original file line number Diff line number Diff line change 1+ package readers
2+
3+ import (
4+ "net/http"
5+
6+ log "github.com/Sirupsen/logrus"
7+ "github.com/matrix-org/util"
8+ )
9+
10+ // Sync handles HTTP requests to /sync
11+ type Sync struct {}
12+
13+ // OnIncomingRequest implements util.JSONRequestHandler
14+ func (s * Sync ) OnIncomingRequest (req * http.Request ) (interface {}, * util.HTTPError ) {
15+ logger := req .Context ().Value (util .CtxValueLogger ).(* log.Entry )
16+ logger .Info ("Doing stuff..." )
17+ return nil , & util.HTTPError {
18+ Code : 404 ,
19+ Message : "Not implemented yet" ,
20+ }
21+ }
Original file line number Diff line number Diff line change 1+ package writers
2+
3+ import (
4+ "net/http"
5+
6+ log "github.com/Sirupsen/logrus"
7+ "github.com/matrix-org/util"
8+ )
9+
10+ // SendMessage handles HTTP requests to /rooms/$room_id/send/$event_type
11+ type SendMessage struct {
12+ }
13+
14+ // OnIncomingRequest implements util.JSONRequestHandler
15+ func (s * SendMessage ) OnIncomingRequest (req * http.Request ) (interface {}, * util.HTTPError ) {
16+ logger := req .Context ().Value (util .CtxValueLogger ).(* log.Entry )
17+ logger .Info ("Doing stuff..." )
18+ return nil , & util.HTTPError {
19+ Code : 404 ,
20+ Message : "Not implemented yet" ,
21+ }
22+ }
You can’t perform that action at this time.
0 commit comments