chore: update main.go
This commit is contained in:
33
main.go
33
main.go
@@ -57,23 +57,26 @@ var (
|
|||||||
// -------------------------------
|
// -------------------------------
|
||||||
|
|
||||||
func request(client *http.Client, method, url string, body interface{}) (*http.Response, error) {
|
func request(client *http.Client, method, url string, body interface{}) (*http.Response, error) {
|
||||||
var buf io.Reader
|
var buf io.Reader
|
||||||
if body != nil {
|
if body != nil {
|
||||||
data, err := json.Marshal(body)
|
data, err := json.Marshal(body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to marshal request body: %w", err)
|
return nil, fmt.Errorf("failed to marshal request body: %w", err)
|
||||||
}
|
}
|
||||||
buf = bytes.NewBuffer(data)
|
buf = bytes.NewBuffer(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest(method, url, buf)
|
req, err := http.NewRequest(method, url, buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to create request: %w", err)
|
return nil, fmt.Errorf("failed to create request: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req.Header.Set("X-API-KEY", portainerToken)
|
req.Header.Set("X-API-KEY", portainerToken)
|
||||||
req.Header.Set("Content-Type", "application/json")
|
if method != "GET" {
|
||||||
return client.Do(req)
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
}
|
||||||
|
|
||||||
|
return client.Do(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------
|
// -------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user