2020-02-10 09:23:10 +00:00
|
|
|
package models
|
|
|
|
|
|
|
|
// BaseMessage is a basic message model, basis of the whole protocol. It is used for a very easy protocol extension process.
|
|
|
|
type BaseMessage struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
MessageType string `json:"type"`
|
2021-04-24 21:56:20 +00:00
|
|
|
From string `json:"from,omitempty"`
|
|
|
|
To string `json:"to,omitempty"`
|
2020-02-10 09:23:10 +00:00
|
|
|
Ok bool `json:"ok"`
|
|
|
|
Payload map[string]interface{} `json:"payload"`
|
|
|
|
}
|
|
|
|
|
2021-04-24 21:56:20 +00:00
|
|
|
func NewBaseMessage(id, messageType, from string, to string, ok bool, payload map[string]interface{}) BaseMessage {
|
2020-02-10 09:23:10 +00:00
|
|
|
return BaseMessage{
|
2020-02-10 10:56:13 +00:00
|
|
|
ID: id,
|
2020-02-10 09:23:10 +00:00
|
|
|
MessageType: messageType,
|
|
|
|
From: from,
|
|
|
|
To: to,
|
|
|
|
Ok: ok,
|
|
|
|
Payload: payload,
|
|
|
|
}
|
|
|
|
}
|
2021-04-24 21:56:20 +00:00
|
|
|
|
|
|
|
func NewEmptyBaseMessage() BaseMessage {
|
|
|
|
return BaseMessage{
|
|
|
|
ID: "",
|
|
|
|
MessageType: "",
|
|
|
|
From: "",
|
|
|
|
To: "",
|
|
|
|
Ok: true,
|
|
|
|
Payload: map[string]interface{}{},
|
|
|
|
}
|
|
|
|
}
|