Commit a7809416 authored by Robert Newton's avatar Robert Newton
Browse files

Provide constructor for events that abstracts the UUID and CreatedAt from the domain

parent b8e5ab0c
......@@ -3,7 +3,11 @@
// happened that has relevance to the domain.
package events
import "time"
import (
uuid ""
// Event is a generic wrapper for all domain events
type Event struct {
......@@ -12,3 +16,15 @@ type Event struct {
Name string `json:"name"`
Data interface{} `json:"data"`
// NewEvent creates a new event with the given name and payload. The UUID and CreatedAt fields
// are filled in automatically so that the infrastructure concerns of doing so are removed from
// the domain
func NewEvent(name string, payload interface{}) *Event {
return &Event{
UUID: uuid.NewV4().String(),
CreatedAt: time.Now(),
Name: name,
Data: payload,
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment