add user service

This commit is contained in:
kandrusyak
2023-06-23 17:24:00 +03:00
parent b3e4b8a5ab
commit eab7ec0c90
12 changed files with 114 additions and 41 deletions

31
pkg/api/apiCall.go Normal file
View File

@@ -0,0 +1,31 @@
package api
import (
"bytes"
"encoding/json"
"io"
"net/http"
)
func PostRequest(url string, model any) ([]byte, error) {
uJson, err := json.Marshal(model)
if err != nil {
return nil, err
}
resp, err := http.Post(url,
"application/json", bytes.NewReader(uJson))
if err != nil {
return nil, err
}
data, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return data, nil
}