32 lines
707 B
Go
32 lines
707 B
Go
package common
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// Event is the generic structure for events sent over Kafka
|
|
type Event struct {
|
|
Topic string `json:"topic"`
|
|
Key string `json:"key"`
|
|
Payload Message `json:"payload"`
|
|
}
|
|
|
|
// EventRawJSON is Event (see above) but keeps payload as raw data
|
|
type EventRawJSON struct {
|
|
Topic string `json:"topic"`
|
|
Key string `json:"key"`
|
|
Payload json.RawMessage `json:"payload"`
|
|
}
|
|
|
|
func (e *EventRawJSON) Marshal() ([]byte, error) {
|
|
data, err := json.Marshal(*e)
|
|
return data, errors.WithStack(err)
|
|
}
|
|
|
|
func (e *EventRawJSON) Unmarshal(data []byte) error {
|
|
err := json.Unmarshal(data, e)
|
|
return errors.WithStack(err)
|
|
}
|