Files
cloud-services/pkg/common/message.go

36 lines
848 B
Go

package common
import (
"encoding/json"
"github.com/pkg/errors"
)
// Message is the generic structure for messages sent over redis and kafka
type Message struct {
Handler string `json:"handler"`
Data interface{} `json:"data,omitempty"`
}
type MessageString struct {
Message string `json:"message"`
}
// MessageRawJSON is Message (see above) but keeps payload as raw data
type MessageRawJSON struct {
Handler string `json:"handler"`
Data json.RawMessage `json:"data"`
Version string `json:"version,omitempty"`
Verify string `json:"verify,omitempty"`
}
func (m *MessageRawJSON) Marshal() ([]byte, error) {
data, err := json.Marshal(*m)
return data, errors.WithStack(err)
}
func (m *MessageRawJSON) Unmarshal(data []byte) error {
err := json.Unmarshal(data, m)
return errors.WithStack(err)
}