From 8cf93a941b1d4969be10e7f7e4f8822c3de1d9b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Floure?= Date: Mon, 6 Apr 2020 18:42:26 +0200 Subject: [PATCH] Initial matrix client wiring --- main.go | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 12aade8..809bc70 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "fmt" "log" "net/http" + "github.com/matrix-org/gomatrix" ) func main() { @@ -13,11 +14,37 @@ func main() { var logger *log.Logger = log.New(os.Stdout, "", log.Flags()) // 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)") 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. - // 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). http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {