domain

package
v0.0.1-0...-6deec57 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2022 License: MIT Imports: 6 Imported by: 0

README

domain GoDoc

Package domain provides interfaces along with helper functions

Download:

go get -u github.com/bradishungry/go-api-learning/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

This section is empty.

Functions

func NewRawEvent

func NewRawEvent(eventType string) (interface{}, error)

func RegisterEventFactory

func RegisterEventFactory(eventType string, factory func() interface{}) error

func UnregisterEventData

func UnregisterEventData(eventType string) error

Types

type Command

type Command interface {
	GetName() string
}

Command type

type Event

type Event struct {
	ID            uuid.UUID      `json:"id"`
	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"`
	ExpiresAt     *time.Time     `json:"expires_at,omitempty"`
	Payload       interface{}    `json:"payload,omitempty"`
	Metadata      *EventMetadata `json:"metadata,omitempty"`
}

Event contains id, payload and metadata

func NewEventFromRawEvent

func NewEventFromRawEvent(streamID uuid.UUID, streamName string, streamVersion int, rawEvent RawEvent) (*Event, error)

NewEventFromRawEvent create new event

Example
package main

import (
	"fmt"
	"github.com/google/uuid"

	"github.com/bradishungry/go-api-learning/pkg/domain"
)

type Test struct {
	Page   int      `json:"page"`
	Fruits []string `json:"fruits"`
}

func (e Test) GetType() string {
	return ""
}

func main() {
	event, _ := domain.NewEventFromRawEvent(
		uuid.New(),
		"streamName",
		0,
		Test{1, []string{"apple", "peach"}},
	)

	fmt.Printf("%v\n", event.StreamName)
	fmt.Printf("%v\n", event.StreamVersion)
	fmt.Printf("%v\n", event.Payload)

}
Output:

streamName
0
{1 [apple peach]}

func (*Event) WithMetadata

func (e *Event) WithMetadata(meta *EventMetadata)

type EventMetadata

type EventMetadata struct {
	Identity  *identity.Identity `json:"identity,omitempty"`
	IPAddress net.IP             `json:"ip_address,omitempty"`
	UserAgent string             `json:"http_user_agent,omitempty"`
	Referer   string             `json:"http_referer,omitempty"`
}

func (*EventMetadata) IsEmpty

func (m *EventMetadata) IsEmpty() bool

type RawEvent

type RawEvent interface {
	GetType() string
}

Jump to

Keyboard shortcuts

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