package client import ( "encoding/json" "log" "time" ) type ClientMessage struct { FromUID string ToUID string Subject string Body string Timestamp time.Time } type ClientMessageInfo struct { Num int FromUID string Timestamp time.Time Subject string } func newClientMessage(fromUID string, toUID string, subject string, body string, timestamp time.Time) ClientMessage { return ClientMessage{FromUID: fromUID, ToUID: toUID, Subject: subject, Body: body, Timestamp: timestamp} } func newClientMessageInfo(num int, fromUID string, subject string, timestamp time.Time) ClientMessageInfo { return ClientMessageInfo{Num:num,FromUID: fromUID,Subject: subject,Timestamp: timestamp} } func Marshal(data any) []byte { subject, err := json.Marshal(data) if err != nil { log.Panicf("Error when marshalling message: %v", err) } return subject } func Unmarshal(data []byte) string { var c string err := json.Unmarshal(data, &c) if err != nil { log.Panicln("Could not unmarshal data") } return c }