From 105657fc4bb2ffeca9389c28119a7706ad5dd750 Mon Sep 17 00:00:00 2001 From: Matt Burchett Date: Thu, 4 Feb 2021 01:26:46 -0600 Subject: [PATCH] making the /generic/ endpoint respond with a message containing the response from Matrix. --- pkg/generic/generic.go | 4 ++-- pkg/matrix/matrix.go | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/pkg/generic/generic.go b/pkg/generic/generic.go index 430b4f6..f7e930b 100644 --- a/pkg/generic/generic.go +++ b/pkg/generic/generic.go @@ -24,9 +24,9 @@ func Handle(cfg config.Config) http.HandlerFunc { log.Error().Err(err).Msg("An error has occurred") } - matrix.PublishText(cfg, vars, reqBody, token) + resp := matrix.PublishText(cfg, vars, reqBody, token) - router.Respond(w, 200, nil) + router.Respond(w, 200, resp) } } diff --git a/pkg/matrix/matrix.go b/pkg/matrix/matrix.go index ec1d1ca..1f3bb11 100644 --- a/pkg/matrix/matrix.go +++ b/pkg/matrix/matrix.go @@ -61,7 +61,7 @@ func GetToken(cfg config.Config, vars map[string]string) string { } // PublishText will publish the data to Matrix using the specified vars. -func PublishText(cfg config.Config, vars map[string]string, data []byte, token string) { +func PublishText(cfg config.Config, vars map[string]string, data []byte, token string) []byte { matrixPublish := struct { MsgType string `json:"msgtype"` Body string `json:"body"` @@ -89,8 +89,7 @@ func PublishText(cfg config.Config, vars map[string]string, data []byte, token s } body, err := ioutil.ReadAll(resp.Body) - fmt.Println(string(body)) - defer resp.Body.Close() + return body }