1
0
mirror of https://github.com/matrix-org/dendrite.git synced 2024-06-15 05:26:40 +00:00
matrix-org.dendrite/src/github.com/matrix-org/dendrite/clientapi/clientapi.go

55 lines
1.4 KiB
Go
Raw Normal View History

package main
import (
"net/http"
"os"
"path/filepath"
"golang.org/x/crypto/ed25519"
"github.com/matrix-org/dendrite/clientapi/config"
"github.com/matrix-org/dendrite/clientapi/routing"
log "github.com/Sirupsen/logrus"
"github.com/matrix-org/dugong"
)
func setupLogging(logDir string) {
_ = os.Mkdir(logDir, os.ModePerm)
log.AddHook(dugong.NewFSHook(
filepath.Join(logDir, "info.log"),
filepath.Join(logDir, "warn.log"),
filepath.Join(logDir, "error.log"),
&log.TextFormatter{
TimestampFormat: "2006-01-02 15:04:05.000000",
DisableColors: true,
DisableTimestamp: false,
DisableSorting: false,
}, &dugong.DailyRotationSchedule{GZip: true},
))
}
func main() {
bindAddr := os.Getenv("BIND_ADDRESS")
if bindAddr == "" {
log.Panic("No BIND_ADDRESS environment variable found.")
}
logDir := os.Getenv("LOG_DIR")
if logDir != "" {
setupLogging(logDir)
}
log.Info("Starting clientapi")
// 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)
}
routing.Setup(http.DefaultServeMux, http.DefaultClient, config.ClientAPI{
ServerName: "localhost",
KeyID: "ed25519:something",
PrivateKey: privKey,
})
log.Fatal(http.ListenAndServe(bindAddr, nil))
}