Documentation ¶
Index ¶
Constants ¶
View Source
const ( ErrAlreadyExists errorkit.Error = "err-already-exists" ErrNotFound errorkit.Error = "err-not-found" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AllDeleter ¶ added in v0.80.0
type ByIDDeleter ¶ added in v0.80.0
type ByIDFinder ¶ added in v0.80.0
type ByIDFinder[Entity, ID any] interface { // FindByID is a function that tries to find an Entity using its ID. // It will inform you if it successfully located the entity or if there was an unexpected issue during the process. // Instead of using an error to represent a "not found" situation, // a return boolean value is used to provide this information explicitly. // // // Why the return signature includes a found bool value? // // This approach serves two key purposes. // First, it ensures that the go-vet tool checks if the 'found' boolean variable is reviewed before using the entity. // Second, it enhances readability and demonstrates the function's cyclomatic complexity. // total: 2^(n+1+1) // -> found/bool 2^(n+1) | An entity might be found or not. // -> error 2^(n+1) | An error might occur or not. // // Additionally, this method prevents returning an initialized pointer type with no value, // which could lead to a runtime error if a valid but nil pointer is given to an interface variable type. // (MyInterface)((*Entity)(nil)) != nil // // Similar approaches can be found in the standard library, // such as SQL null value types and environment lookup in the os package. FindByID(ctx context.Context, id ID) (ent Entity, found bool, err error) }
type Creator ¶
type Creator[Entity any] interface { // Create is a function that takes a pointer to an entity and stores it in an external resource. // And external resource could be a backing service like PostgreSQL. // The use of a pointer type allows the function to update the entity's ID value, // which is significant in both the external resource and the domain layer. // The ID is essential because entities in the backing service are referenced using their IDs, // which is why the ID value is included as part of the entity structure fieldset. // // The pointer is also employed for other fields managed by the external resource, such as UpdatedAt, CreatedAt, // and any other fields present in the domain entity but controlled by the external resource. Create(ctx context.Context, ptr *Entity) error }
type Deleter ¶
type Deleter[ID any] interface { ByIDDeleter[ID] AllDeleter }
Deleter request to destroy a business entity in the Resource that implement it's test.
type Finder ¶
type Finder[Entity, ID any] interface { ByIDFinder[Entity, ID] AllFinder[Entity] }
type Purger ¶
type Purger interface { // Purge will completely wipe all state from the given resource. // It is meant to be used in testing during clean-ahead arrangements. Purge(context.Context) error }
Purger supplies functionality to purge a resource completely. On high level this looks similar to what Deleter do, but in case of an event logged resource, this will purge all the events. After a purge, it is not expected to have anything in the repository. It is heavily discouraged to use Purge for domain interactions.
type Saver ¶ added in v0.151.0
type Saver[Entity any] interface { // Save combines the behaviour of Creator and Updater in a single functionality. // If the entity is absent in the resource, the entity is created based on the Creator's behaviour. // If the entity is present in the resource, the entity is updated based on the Updater's behaviour. // Save requires the entity to have a valid non-empty ID value. Save(ctx context.Context, ptr *Entity) error }
type Updater ¶
type Updater[Entity any] interface { // Update will take a pointer to an entity and update the stored entity data by the values in received entity. // The Entity must have a valid ID field, which referencing an existing entity in the external resource. Update(ctx context.Context, ptr *Entity) error }
Click to show internal directories.
Click to hide internal directories.