generic send instructions method

This commit is contained in:
Baipyrus 2024-04-12 10:03:36 +02:00
parent 2e62aa5579
commit 90f577820e

17
main.go
View File

@ -115,6 +115,20 @@ func LoadMatrixData() (string, int, int) {
return url, width, height 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() { func main() {
// Load .env file if it exists // Load .env file if it exists
err := godotenv.Load(".env") err := godotenv.Load(".env")
@ -132,4 +146,7 @@ func main() {
col := Color{R: 255, G: 0, B: 255, endpoint: COLOR} col := Color{R: 255, G: 0, B: 255, endpoint: COLOR}
rct := Rectangle{X: 0, Y: 0, W: 10, H: 10, endpoint: RECTANGLE} rct := Rectangle{X: 0, Y: 0, W: 10, H: 10, endpoint: RECTANGLE}
upd := Update{endpoint: UPDATE} upd := Update{endpoint: UPDATE}
// Send request to remote server
SendRequest(client, url, []interface{}{col, rct, upd})
} }