Files
durpot/handlers/shared.go
2023-06-06 19:13:41 -04:00

39 lines
768 B
Go

package handlers
import (
"encoding/base64"
"fmt"
"io"
"net/http"
)
func CallDurpAPI(url string, username string, password string) []byte {
req, err := http.NewRequest("GET", url, nil)
if err != nil {
fmt.Println("Error creating request:", err)
return nil
}
auth := username + ":" + password
basicAuth := "Basic " + base64.StdEncoding.EncodeToString([]byte(auth))
req.Header.Set("Authorization", basicAuth)
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error sending request:", err)
return nil
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading response:", err)
return nil
}
return body
}