32 lines
558 B
Go
32 lines
558 B
Go
package networking
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
)
|
|
|
|
func GetJsonBody(url string) []byte {
|
|
req, err := http.Get(url)
|
|
if err != nil {
|
|
fmt.Printf("Failed to send request %v\n", err)
|
|
}
|
|
|
|
body, err := io.ReadAll(req.Body)
|
|
if err != nil {
|
|
fmt.Printf("Failed to read request body %v\n", err)
|
|
}
|
|
|
|
return body
|
|
}
|
|
|
|
func PostJsonBody(url string, json []byte) int {
|
|
req, err := http.Post(url, "application/json", bytes.NewBuffer(json))
|
|
if err != nil {
|
|
fmt.Printf("Failed to send post request on server: %v\n", err)
|
|
}
|
|
|
|
return req.StatusCode
|
|
}
|