-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathytmd.go
41 lines (35 loc) · 796 Bytes
/
ytmd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func ytmdCmd(address string, token string, playerCmd string) error {
// Define the JSON data you want to send
data := map[string]interface{}{
"command": playerCmd,
"data": "",
}
// Convert the JSON data to bytes
jsonData, err := json.Marshal(data)
if err != nil {
return err
}
path := "/api/v1/command"
url := "http://" + address + path
client := &http.Client{}
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
if err != nil {
return err
}
req.Header.Set("Authorization", token)
req.Header.Set("Content-Type", "application/json")
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error sending request:", err)
return err
}
defer resp.Body.Close()
return err
}