meowlib/client/helpers/networkHelper.go
ycc 6867086c4f
Some checks failed
continuous-integration/drone/push Build is failing
Http helper function added
2024-03-25 13:24:43 +01:00

31 lines
696 B
Go

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