domain

package
v0.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2020 License: MIT Imports: 4 Imported by: 0

README

domain GoDoc

Package domain provides interfaces along with helper functions

Download:

go get -u github.com/vardius/go-api-boilerplate/pkg/domain

Package domain provides interfaces along with helper functions

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

View Source
var NullEvent = Event{}

NullEvent represents empty event

Functions

This section is empty.

Types

type Command

type Command interface {
	GetName() string
}

Command type

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"]}

type EventMetaData

type EventMetaData struct {
	Type          string    `json:"type"`
	StreamID      uuid.UUID `json:"stream_id"`
	StreamName    string    `json:"stream_name"`
	StreamVersion int       `json:"stream_version"`
	OccurredAt    time.Time `json:"occurred_at"`
}

EventMetaData for Event

type RawEvent

type RawEvent interface {
	GetType() string
}

RawEvent represents raw event that it is aware of its type

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL