6
1
mirror of https://git.mills.io/saltyim/saltyim.git synced 2024-06-30 18:51:03 +00:00
prologic-saltyim/sendmsg.go
xuu 78417dd472 feat: add send message functionality (#8)
I added sha256 for discovery and fallback ability.
And implemented sending message using msgbus.

Co-authored-by: Jon Lundy <jon@xuu.cc>
Reviewed-on: https://git.mills.io/prologic/salty-chat/pulls/8
Co-authored-by: xuu <xuu@noreply@mills.io>
Co-committed-by: xuu <xuu@noreply@mills.io>
2022-03-18 22:50:04 +00:00

21 lines
430 B
Go

package saltyim
import (
"strings"
msgbus_client "git.mills.io/prologic/msgbus/client"
)
func Send(endpoint, msg string) error {
uri, topic := splitTopic(endpoint)
client := msgbus_client.NewClient(uri, nil)
return client.Publish(topic, msg)
}
func splitTopic(endpoint string) (string, string) {
if idx := strings.LastIndex(endpoint, "/"); idx != -1 {
return endpoint[:idx], endpoint[idx+1:]
}
return endpoint, ""
}