Initial cloud-services repo - gateway service + pkg modules
This commit is contained in:
35
pkg/common/message.go
Normal file
35
pkg/common/message.go
Normal file
@@ -0,0 +1,35 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user