meowlib/client/helpers/networkHelper.go

31 lines
718 B
Go
Raw Permalink Normal View History

2024-03-25 13:24:43 +01:00
package helpers
import (
"forge.redroom.link/yves/meowlib"
"forge.redroom.link/yves/meowlib/client"
)
2024-04-20 22:29:22 +02:00
func HttpSendMessage(serverUid string, message []byte, timeout int) ([]byte, error) {
2024-03-25 13:24:43 +01:00
id := client.GetConfig().GetIdentity()
srv, err := id.MessageServers.LoadServer(serverUid)
if err != nil {
return nil, err
}
// gettig server Public key if missing
if srv.PublicKey == "" {
srvdata, err := meowlib.HttpGetId(srv.Url)
if err != nil {
return nil, err
}
//print(srvdata["publicKey"])
srv.PublicKey = srvdata["publicKey"]
id.MessageServers.StoreServer(srv)
}
2024-04-20 22:29:22 +02:00
response, err := meowlib.HttpPostMessage(srv.Url, message, timeout)
2024-03-25 13:24:43 +01:00
if err != nil {
return nil, err
}
return response, nil
}