Added message Logging

This commit is contained in:
2021-09-16 15:45:36 +02:00
parent 83bb549c41
commit 9ccd413399
2 changed files with 25 additions and 6 deletions

13
main.go
View File

@@ -1,6 +1,7 @@
package main
import (
"fmt"
"log"
"time"
@@ -8,6 +9,8 @@ import (
xmppService "github.com/xmpploadtesting/services"
)
var layout = "2006-01-02T15:04:05.000Z"
func main() {
// LOAD APPLICATION CONFIGURATION
@@ -25,13 +28,21 @@ func main() {
// Send online presence stanza in go rutines
go func(xmppClient xmppService.XMPPClient) {
log.Printf("online presence stanza FOR %v", xmppClient.Config.Jid)
log.Printf("Online presence stanza FOR %v", xmppClient.Config.Jid)
err := xmppService.SendOnlinePresenceStanza(xmppClient.Client, xmppClient.Config.Jid)
if err != nil {
log.Printf("There was an error while sending online presence stanza %v", err)
return
}
str := "2014-11-12T11:45:26.371Z"
t, err := time.Parse(layout, str)
if err != nil {
fmt.Println(err)
}
fmt.Println(t)
}(xmppClient)
}

View File

@@ -63,6 +63,8 @@ type ClientCredentials struct {
Ping int `json:"ping"`
}
const format = "2006/01/02 15:04:05"
// Instance - get instance of xmpp service
func Instance() *XMPPService {
return &xmppService
@@ -141,8 +143,13 @@ func SendOnlinePresenceStanza(client *xmpp.Client, jid string) error {
onlinePresencePacket.Status = rolingStockPresenceMessage
err := client.Send(onlinePresencePacket)
log.Printf("Sending online presence stanza: %v", err)
return err
if err != nil {
return err
}
log.Printf("<%v> sent online status", jid)
return nil
}
func getClientConfigsFromFile(filePath string) ([]ClientCredentials, error) {
@@ -172,7 +179,7 @@ func getClientConfigsFromFile(filePath string) ([]ClientCredentials, error) {
}
func handleMessage(s xmpp.Sender, p stanza.Packet) {
log.Printf("Handle message")
msg, ok := p.(stanza.Message)
if !ok {
log.Printf(" message not OK")
@@ -180,8 +187,9 @@ func handleMessage(s xmpp.Sender, p stanza.Packet) {
return
}
log.Printf("Received The message %v", msg)
_, _ = fmt.Fprintf(os.Stdout, "Body = %s - from = %s\n", msg.Body, msg.From)
log.Printf("<%v> received following message: %v", msg.To, msg.Body)
// _, _ = fmt.Fprintf(os.Stdout, "Body = %s - from = %s\n", msg.Body, msg.From)
reply := stanza.Message{Attrs: stanza.Attrs{To: msg.From}, Body: `{"status": "OK"}`}
err := s.Send(reply)