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