From 90f577820e1142de04684e10ec585a4a13fc4419 Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Fri, 12 Apr 2024 10:03:36 +0200 Subject: [PATCH] generic send instructions method --- main.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/main.go b/main.go index c9a64af..4b90580 100644 --- a/main.go +++ b/main.go @@ -115,6 +115,20 @@ func LoadMatrixData() (string, int, int) { return url, width, height } +func SendRequest(client *resty.Client, url string, ins []interface{}) { + resp, err := client.R(). + SetHeader("Content-Type", "application/json"). + SetBody(ins). + Post(fmt.Sprintf("%s/instructions", url)) + + if err != nil { + log.Fatal(err) + return + } + + log.Printf("Response Status: %s\n", resp.Status()) +} + func main() { // Load .env file if it exists err := godotenv.Load(".env") @@ -132,4 +146,7 @@ func main() { col := Color{R: 255, G: 0, B: 255, endpoint: COLOR} rct := Rectangle{X: 0, Y: 0, W: 10, H: 10, endpoint: RECTANGLE} upd := Update{endpoint: UPDATE} + + // Send request to remote server + SendRequest(client, url, []interface{}{col, rct, upd}) }