Help us shape the future of Go! Take the 2026 Go Developer Survey

memory

package
v2.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package memory provides the business logic layer for observation management.

The Service implements domain-level validation, default value handling, and orchestrates persistence operations through the ObservationRepository interface. This is the primary entry point for all observation-related operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Service

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

Service provides business logic for observation management. It wraps an ObservationRepository and adds validation, defaults, and domain rules enforcement.

func NewService

func NewService(repo domain.ObservationRepository) *Service

NewService creates a new memory Service with the given repository.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, id int64) error

Delete removes an observation by ID. This performs a soft delete by default.

func (*Service) Get

func (s *Service) Get(ctx context.Context, id int64) (*domain.Observation, error)

Get retrieves an observation by its ID. Returns ErrNotFound if the observation doesn't exist.

func (*Service) GetByTopicKey

func (s *Service) GetByTopicKey(ctx context.Context, project, topicKey string) (*domain.Observation, error)

GetByTopicKey retrieves an observation by its topic key within a project. This is used for upsert operations where topic_key enforces uniqueness. Returns ErrNotFound if no matching observation exists.

func (*Service) List

List retrieves observations based on filter criteria. An empty filter returns all observations up to the default limit.

func (*Service) Save

func (s *Service) Save(ctx context.Context, obs *domain.Observation) error

Save creates or updates an observation.

Business Rules:

  • Title and Content are required (validation error if empty)
  • Type defaults to "manual" if empty
  • Scope defaults to "project" if empty
  • CreatedAt is set to now for new observations
  • UpdatedAt is always set to now

func (*Service) Update

func (s *Service) Update(ctx context.Context, obs *domain.Observation) error

Update modifies an existing observation.

Business Rules:

  • Title and Content are required (validation error if empty)
  • UpdatedAt is always set to now
  • CreatedAt is preserved

func (*Service) UpsertByTopicKey

func (s *Service) UpsertByTopicKey(ctx context.Context, obs *domain.Observation) error

UpsertByTopicKey creates or updates an observation based on its topic key.

Business Rules:

  • If an observation with the same topic_key exists in the project, update it
  • Otherwise, create a new observation
  • Topic key is normalized (lowercase, trimmed)
  • All validation rules from Save apply

Jump to

Keyboard shortcuts

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