This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package aggregate_test | |
import ( | |
"testing" | |
"github.com/percybolmer/ddd-go/aggregate" | |
) | |
func TestCustomer_NewCustomer(t *testing.T) { | |
// Build our needed testcase data struct |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package valueobject | |
import ( | |
"time" | |
) | |
// Transaction is a payment between two parties | |
type Transaction struct { | |
// all values lowercase since they are immutable | |
amount int |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |