meowlib/client/helpers/networkHelper.go
ycc d14cd161da
Some checks failed
continuous-integration/drone/push Build is failing
manage http timeout to allow long poll
2024-04-20 22:29:22 +02:00

31 lines
718 B
Go

package helpers
import (
"forge.redroom.link/yves/meowlib"
"forge.redroom.link/yves/meowlib/client"
)
func HttpSendMessage(serverUid string, message []byte, timeout int) ([]byte, error) {
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)
}
response, err := meowlib.HttpPostMessage(srv.Url, message, timeout)
if err != nil {
return nil, err
}
return response, nil
}