Documentation ¶
Overview ¶
Package domain is the heart layer of the software, and this is where the interesting stuff happens. The objects in this layer contain the data and the logic to manipulate that data, that is specific to the Domain itself and it’s independent of the business processes that trigger that logic, they are independent and completely unaware of the Application Layer. There is one package per aggregate and to each aggregate belongs entities, value objects, domain events, a repository interface and sometimes factories. The core of the business logic, such as determining whether a handling event should be registered. The structure and naming of aggregates, classes and methods in the domain layer should follow the ubiquitous language, and you should be able to explain to a domain expert how this part of the software works by drawing a few simple diagrams and using the actual class and method names of the source code.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var NullEvent = Event{}
NullEvent represents empty event
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct { ID uuid.UUID `json:"id"` Metadata EventMetaData `json:"metadata"` Payload json.RawMessage `json:"payload"` }
Event contains id, payload and metadata
func MakeEvent ¶
func MakeEvent(meta EventMetaData, payload json.RawMessage) (Event, error)
MakeEvent makes a event object from metadata and payload
Example ¶
package main import ( "fmt" "time" "github.com/google/uuid" "github.com/vardius/go-api-boilerplate/pkg/domain" ) func main() { event, _ := domain.MakeEvent( domain.EventMetaData{ Type: "type", StreamID: uuid.New(), StreamName: "streamName", StreamVersion: 0, OccurredAt: time.Now(), }, []byte(`{"page":1,"fruits":["apple","peach"]}`), ) fmt.Printf("%v\n", event.Metadata.StreamName) fmt.Printf("%v\n", event.Metadata.StreamVersion) fmt.Printf("%s\n", event.Payload) }
Output: streamName 0 {"page":1,"fruits":["apple","peach"]}
func NewEvent ¶
func NewEvent(streamID uuid.UUID, streamName string, streamVersion int, rawEvent RawEvent) (Event, error)
NewEvent create new event
Example ¶
package main import ( "fmt" "github.com/google/uuid" "github.com/vardius/go-api-boilerplate/pkg/domain" ) type Test struct { Page int `json:"page"` Fruits []string `json:"fruits"` } func (e Test) GetType() string { return "" } func main() { event, _ := domain.NewEvent( uuid.New(), "streamName", 0, Test{1, []string{"apple", "peach"}}, ) fmt.Printf("%v\n", event.Metadata.StreamName) fmt.Printf("%v\n", event.Metadata.StreamVersion) fmt.Printf("%s\n", event.Payload) }
Output: streamName 0 {"page":1,"fruits":["apple","peach"]}