add uid to peer + helper methods + http
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
ycc
2024-03-23 20:09:14 +01:00
parent 0a70206b11
commit f80411bf21
11 changed files with 715 additions and 1 deletions

40
http.go Normal file
View File

@ -0,0 +1,40 @@
package meowlib
import (
"bytes"
"encoding/json"
"io"
"net/http"
)
func HttpGetId(url string) (response map[string]string, err error) {
srvId := make(map[string]string)
resp, err := http.Get(url + "/id")
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
err = json.Unmarshal(body, &srvId)
if err != nil {
return nil, err
}
return srvId, nil
}
func HttpPostMessage(url string, msg []byte) (response []byte, err error) {
resp, err := http.Post(url+"/msg",
"application/octet-stream", bytes.NewBuffer(msg))
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return body, nil
}