Files
Archive/echo/pkg/http/http.go
2024-03-17 19:25:58 +01:00

23 lines
400 B
Go

package http
import (
"bytes"
"encoding/json"
"io"
"net/http"
)
func PostJson(c *http.Client, url string, dataStruct interface{}) error {
buf := new(bytes.Buffer)
if err := json.NewEncoder(buf).Encode(dataStruct); err != nil {
return err
}
r, err := http.Post(url, "application/json", buf)
if err != nil {
return err
}
defer r.Body.Close()
_, err = io.ReadAll(r.Body)
return err
}