main.go 1.5 KB
Newer Older
1 2 3 4 5
package main

import (
	"net/http"
	"os"
6

7 8 9
	"golang.org/x/crypto/ed25519"

	"github.com/matrix-org/dendrite/clientapi/config"
10
	"github.com/matrix-org/dendrite/clientapi/producers"
11
	"github.com/matrix-org/dendrite/clientapi/routing"
12
	"github.com/matrix-org/dendrite/common"
13
	"github.com/matrix-org/dendrite/roomserver/api"
14 15 16 17 18 19 20 21 22

	log "github.com/Sirupsen/logrus"
)

func main() {
	bindAddr := os.Getenv("BIND_ADDRESS")
	if bindAddr == "" {
		log.Panic("No BIND_ADDRESS environment variable found.")
	}
23 24
	logDir := os.Getenv("LOG_DIR")
	if logDir != "" {
25
		common.SetupLogging(logDir)
26
	}
K
Kegsay 已提交
27

28 29 30 31 32 33
	// TODO: Rather than generating a new key on every startup, we should be
	//       reading a PEM formatted file instead.
	_, privKey, err := ed25519.GenerateKey(nil)
	if err != nil {
		log.Panicf("Failed to generate private key: %s", err)
	}
K
Kegsay 已提交
34 35 36 37 38 39

	cfg := config.ClientAPI{
		ServerName:           "localhost",
		KeyID:                "ed25519:something",
		PrivateKey:           privKey,
		KafkaProducerURIs:    []string{"localhost:9092"},
40 41
		ClientAPIOutputTopic: "roomserverInput",
		RoomserverURL:        "http://localhost:7777",
K
Kegsay 已提交
42 43 44 45
	}

	log.Info("Starting clientapi")

46
	roomserverProducer, err := producers.NewRoomserverProducer(cfg.KafkaProducerURIs, cfg.ClientAPIOutputTopic)
K
Kegsay 已提交
47 48 49
	if err != nil {
		log.Panicf("Failed to setup kafka producers(%s): %s", cfg.KafkaProducerURIs, err)
	}
50

51
	queryAPI := api.NewRoomserverQueryAPIHTTP(cfg.RoomserverURL, nil)
K
Kegsay 已提交
52

53
	routing.Setup(http.DefaultServeMux, http.DefaultClient, cfg, roomserverProducer, queryAPI)
54 55
	log.Fatal(http.ListenAndServe(bindAddr, nil))
}