Skip to content

Instantly share code, notes, and snippets.

View percybolmer's full-sized avatar

ProgrammingPercy percybolmer

View GitHub Profile
// GetID returns the customers root entity ID
func (c *Customer) GetID() uuid.UUID {
return c.person.ID
}
// SetID sets the root ID
func (c *Customer) SetID(id uuid.UUID) {
if c.person == nil {
c.person = &entity.Person{}
}
c.person.ID = id
// Package memory is a in-memory implementation of the customer repository
package memory
import (
"sync"
"github.com/google/uuid"
"github.com/percybolmer/ddd-go/aggregate"
)
// Package Customer holds all the domain logic for the customer domain.
package customer
import (
"github.com/google/uuid"
"github.com/percybolmer/ddd-go/aggregate"
)
var (
// ErrCustomerNotFound is returned when a customer is not found.
ErrCustomerNotFound = errors.New("the customer was not found in the repository")
package aggregate_test
import (
"testing"
"github.com/percybolmer/ddd-go/aggregate"
)
func TestCustomer_NewCustomer(t *testing.T) {
// Build our needed testcase data struct
// Package aggregate holds aggregates that combines many entities into a full object
package aggregate
import (
"errors"
"github.com/google/uuid"
"github.com/percybolmer/ddd-go/entity"
"github.com/percybolmer/ddd-go/valueobject"
)
func NewClient(cfg Config) (*Client, error) {
var addrs []string
if len(cfg.Addresses) == 0 && cfg.CloudID == "" {
addrs = addrsFromEnvironment()
} else {
if len(cfg.Addresses) > 0 && cfg.CloudID != "" {
return nil, errors.New("cannot create client: both Addresses and CloudID are set")
}
@percybolmer
percybolmer / Go-DDD-Customer.go
Last active September 4, 2021 17:41
#ddd-tavern
// Package aggregates holds aggregates that combines many entities into a full object
package aggregate
import (
"github.com/percybolmer/ddd-go/entity"
"github.com/percybolmer/ddd-go/valueobject"
)
// Customer is a aggregate that combines all entities needed to represent a customer
type Customer struct {
@percybolmer
percybolmer / Go-DDD-Transaction.go
Last active September 4, 2021 18:51
#ddd-tavern
package valueobject
import (
"time"
)
// Transaction is a payment between two parties
type Transaction struct {
// all values lowercase since they are immutable
amount int
@percybolmer
percybolmer / Go-DDD-Item.go
Last active September 4, 2021 17:29
#ddd-tavern
package entity
import "github.com/google/uuid"
// Item represents a Item for all sub domains
type Item struct {
ID uuid.UUID
Name string
Description string
}
@percybolmer
percybolmer / Go-DDD-Person.go
Last active September 4, 2021 17:28
#ddd-tavern
// Package entities holds all the entities that are shared across all subdomains
package entity
import (
"github.com/google/uuid"
)
// Person is a entity that represents a person in all Domains
type Person struct {
// ID is the identifier of the Entity, the ID is shared for all sub domains