Categorygithub.com/tangelo-labs/go-domain
modulepackage
0.0.6
Repository: https://github.com/tangelo-labs/go-domain.git
Documentation: pkg.go.dev

# README

Domain

This package provides basic definitions for building application domain models in Go following a DDD approach.

Things included are:

  • Entity identifiers generator.
  • Domain event recording traits.
  • Domain event dispatching and publishing definitions.
  • Continuation token pagination primitives.

Installation

go get github.com/tangelo-labs/go-domain

Example

Defining aggregate roots:

package main

import (
    "github.com/tangelo-labs/go-domain"
)

type NameChangedEvent struct {
	ID      domain.ID
    Before  string
    After   string
}

type User struct {
    id      domain.ID
    name    string
    age     int

    events.BaseRecorder
}

func NewUser(id domain.ID) *User {
    return &User{
        id: id,
    }
}

func (u *User) ID() domain.ID {
    return u.id
}

func (u *User) ChangeName(n string) {   
    u.Record(NameChangedEvent{
        ID: u.ID(),
        Before: u.name,
        After: n,
    })
    
     u.name = n    
}

See the "examples" directory for more complete example.

# Packages

No description provided by the author
No description provided by the author
Package pagination provides generic definitions for implementing `Timestamp_ID` Continuation Token pagination algorithm.

# Functions

NewID creates a new ID using an ULID generator.
SetIDGenerator sets the ID generator function.

# Variables

ULIDGenerator is the default ID generator function that uses ULID algorithm.
UUIDGenerator is an ID generator function that uses UUID algorithm.

# Interfaces

AggregateRoot is the base interface for all domain aggregate roots.
Entity is the base interface for all domain entities.

# Type aliases

ID defines a globally unique identifier for an Entity.
IDs a convenience definition for dealing with collection of IDs in memory.