user

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package user serves as a small domain example of how to model an Aggregate using go-eventually.

This package is used for integration tests in the parent module.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidFirstName = errors.New("user: invalid first name, is empty")
	ErrInvalidLastName  = errors.New("user: invalid last name, is empty")
	ErrInvalidEmail     = errors.New("user: invalid email name, is empty")
	ErrInvalidBirthDate = errors.New("user: invalid birthdate, is empty")
)

All the errors returned by User methods.

View Source
var ErrNotFound = errors.New("user: not found")

ErrNotFound is returned by a Query when a specific User has not been found.

View Source
var EventProtoSerde = serde.Fused[message.Message, *userv1.Event]{
	Serializer:   serde.SerializerFunc[message.Message, *userv1.Event](protoEventSerializer),
	Deserializer: serde.DeserializerFunc[message.Message, *userv1.Event](protoEventDeserializer),
}

EventProtoSerde is the serde.Serde implementation for User domain events to map to their Protobuf type, defined in the proto/ folder.

View Source
var ProtoSerde = serde.Fused[*User, *userv1.User]{
	Serializer:   serde.SerializerFunc[*User, *userv1.User](protoSerializer),
	Deserializer: serde.DeserializerFunc[*User, *userv1.User](protoDeserializer),
}

ProtoSerde is the serde.Serde implementation for a User to map to its Protobuf type, defined in the proto/ folder.

View Source
var Type = aggregate.Type[uuid.UUID, *User]{
	Name:    "User",
	Factory: func() *User { return new(User) },
}

Type is the User aggregate type.

Functions

func AggregateRepositorySuite

func AggregateRepositorySuite(repository aggregate.Repository[uuid.UUID, *User]) func(t *testing.T)

AggregateRepositorySuite returns an executable testing suite running on the agfgregate.Repository value provided in input.

The aggregate.Repository value requested should comply with the given signature.

Package user of this module exposes a Protobuf-based serde, which can be useful to test serialization and deserialization of data to the target repository implementation.

func EventStoreSuite

func EventStoreSuite(eventStore event.Store) func(t *testing.T)

EventStoreSuite returns an executable testing suite running on the event.Store value provided in input.

Types

type CreateCommand

type CreateCommand struct {
	FirstName, LastName string
	BirthDate           time.Time
	Email               string
}

CreateCommand is a domain command that can be used to create a new User.

func (CreateCommand) Name

func (CreateCommand) Name() string

Name implements command.Command.

type CreateCommandHandler

type CreateCommandHandler struct {
	Clock          func() time.Time
	UUIDGenerator  func() uuid.UUID
	UserRepository aggregate.Saver[uuid.UUID, *User]
}

CreateCommandHandler is the command handler for CreateCommand domain commands.

func (CreateCommandHandler) Handle

Handle implements command.Handler.

type EmailWasUpdated

type EmailWasUpdated struct {
	Email string
}

EmailWasUpdated is the domain event fired after a User email is updated.

func (*EmailWasUpdated) Name

func (*EmailWasUpdated) Name() string

Name implements message.Message.

type Event

type Event struct {
	ID         uuid.UUID
	RecordTime time.Time
	Kind       eventKind
}

Event represents a Domain Event for a User resource.

func (*Event) Name

func (evt *Event) Name() string

Name implements event.Event.

type GetByEmail

type GetByEmail string

GetByEmail is a Domain Query that can be used to fetch a specific User given its email.

func (GetByEmail) Name

func (GetByEmail) Name() string

Name implements query.Query.

type GetByEmailHandler

type GetByEmailHandler struct {
	// contains filtered or unexported fields
}

GetByEmailHandler is a stateful Query Handler that maintains a list of Users indexed by their email.

It can be used to answer GetByEmail queries.

GetByEmailHandler is thread-safe.

func NewGetByEmailHandler

func NewGetByEmailHandler() *GetByEmailHandler

NewGetByEmailHandler creates a new GetByEmailHandler instance.

func (*GetByEmailHandler) Handle

func (handler *GetByEmailHandler) Handle(_ context.Context, q query.Envelope[GetByEmail]) (View, error)

Handle implements query.Handler.

func (*GetByEmailHandler) Process

func (handler *GetByEmailHandler) Process(_ context.Context, evt event.Persisted) error

Process implements event.Processor.

type User

type User struct {
	aggregate.BaseRoot
	// contains filtered or unexported fields
}

User is a naive user implementation, modeled as an Aggregate using go-eventually's API.

func Create

func Create(id uuid.UUID, firstName, lastName, email string, birthDate, now time.Time) (*User, error)

Create creates a new User using the provided input.

func (*User) AggregateID

func (user *User) AggregateID() uuid.UUID

AggregateID implements aggregate.Root.

func (*User) Apply

func (user *User) Apply(evt event.Event) error

Apply implements aggregate.Aggregate.

func (*User) UpdateEmail

func (user *User) UpdateEmail(email string, now time.Time, metadata message.Metadata) error

UpdateEmail updates the User email with the specified one.

type View

type View struct {
	ID                  uuid.UUID
	Email               string
	FirstName, LastName string
	BirthDate           time.Time

	Version version.Version // NOTE: used to avoid re-processing of already-processed events.
}

View is a public-facing representation of a User entity. Can be obtained through a Query handler.

type WasCreated

type WasCreated struct {
	FirstName string
	LastName  string
	BirthDate time.Time
	Email     string
}

WasCreated is the domain event fired after a User is created.

func (*WasCreated) Name

func (*WasCreated) Name() string

Name implements message.Message.

Directories

Path Synopsis
gen

Jump to

Keyboard shortcuts

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