24 lines
482 B
Go
24 lines
482 B
Go
package common
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// Payload is the generic structure for payloads sent within Kafka messages
|
|
type Payload struct {
|
|
Handler string `json:"handler"`
|
|
Data json.RawMessage `json:"data"`
|
|
}
|
|
|
|
func (p *Payload) Marshal() ([]byte, error) {
|
|
data, err := json.Marshal(*p)
|
|
return data, errors.WithStack(err)
|
|
}
|
|
|
|
func (p *Payload) Unmarshal(data []byte) error {
|
|
err := json.Unmarshal(data, p)
|
|
return errors.WithStack(err)
|
|
}
|