Skip to content
This repository was archived by the owner on Nov 25, 2024. It is now read-only.

Commit 5b5c209

Browse files
authored
Merge pull request #2 from matrix-org/kegan/client-webserver
Add stub clientapi webserver with readers/writers packages
2 parents f87f767 + b04dfae commit 5b5c209

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
}

0 commit comments

Comments
 (0)