Initial matrix client wiring

This commit is contained in:
Timothée Floure 2020-04-06 18:42:26 +02:00
parent c29a6832be
commit 8cf93a941b

29
main.go
View file

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"log" "log"
"net/http" "net/http"
"github.com/matrix-org/gomatrix"
) )
func main() { func main() {
@ -13,11 +14,37 @@ func main() {
var logger *log.Logger = log.New(os.Stdout, "", log.Flags()) var logger *log.Logger = log.New(os.Stdout, "", log.Flags())
// Handle command-line arguments. // Handle command-line arguments.
var homeserver = flag.String("homeserver", "https://matrix.org", "Address of Matrix homeserver")
var user = flag.String("user", "", "Full MXID (e.g. @example.domain.tld) of Matrix user")
var token = flag.String("token", "", "Access Token of Matrix user")
var target = flag.String("target-room", "", "Matrix room to be notified of alerts.")
var port = flag.Int("port", 9088, "HTTP port to listen on (incoming alertmanager webhooks)") var port = flag.Int("port", 9088, "HTTP port to listen on (incoming alertmanager webhooks)")
flag.Parse() flag.Parse()
if *user == "" {
logger.Fatal("Matrix user is required. See --help for usage.")
}
if *token == "" {
logger.Fatal("Matrix access token is required. See --help for usage.")
}
if *target== "" {
logger.Fatal("Matrix target room is required. See --help for usage.")
}
// Initialize Matrix client. // Initialize Matrix client.
// TODO matrixClient, err := gomatrix.NewClient(*homeserver, *user, *token)
if err != nil {
logger.Fatalf("Could not log in to Matrix (%v): %v", *homeserver, err)
}
/*
logger.Printf("Syncing with Matrix homserver (%v)", *homeserver)
err = matrixClient.Sync()
if err != nil {
logger.Fatalf("Could not sync with Matrix homeserver (%v): %v", *homeserver, err)
}
*/
_ = matrixClient
// Initialize HTTP serve (= listen for incoming requests). // Initialize HTTP serve (= listen for incoming requests).
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {