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

scan

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package scan models one execution of the Cortex engine.

A Scan groups everything produced by running N scanners against a git revision: its findings, timing, status, and the rules each scanner used.

Aggregate root: Scan Value Objects: ScanID, Revision, Status (sum type), Duration Domain Events: Started, Completed, Failed

Status transitions are explicit and validated:

Queued → Running → Completed
                 ↘ Failed

Index

Constants

View Source
const UnknownRevisionCommit = "unknown"

UnknownRevisionCommit marks a Scan whose git revision could not be resolved — a tarball, a vendored copy, any target outside a repository. Baseline and differential features degrade gracefully for such scans.

Variables

This section is empty.

Functions

func NewID

func NewID(raw string) mo.Result[ID]

NewID validates and constructs an ID.

func NewRevision

func NewRevision(commit, branch string) mo.Result[Revision]

NewRevision validates and constructs a Revision. branch may be empty when scanning a detached HEAD or a tarball.

Types

type Completed

type Completed struct {
	ID            ID
	At            time.Time
	FindingsCount int
}

Completed is recorded on transition Running → Completed.

func (Completed) EventName

func (Completed) EventName() string

type DomainEvent

type DomainEvent interface {
	EventName() string
}

DomainEvent is implemented by every event recorded by the Scan aggregate.

type Failed

type Failed struct {
	ID     ID
	At     time.Time
	Reason string
}

Failed is recorded on any → Failed transition.

func (Failed) EventName

func (Failed) EventName() string

type ID

type ID string

ID identifies a Scan instance. Generation is the application layer's responsibility (typically a UUID via an injected IDGenerator port).

func (ID) Empty

func (id ID) Empty() bool

func (ID) String

func (id ID) String() string

type Queued

type Queued struct {
	ID       ID
	Revision Revision
}

Queued is recorded the moment a Scan is constructed.

func (Queued) EventName

func (Queued) EventName() string

type Revision

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

Revision describes the git revision under analysis.

func UnknownRevision

func UnknownRevision() Revision

UnknownRevision is the fallback Revision for non-repository targets.

func (Revision) Branch

func (r Revision) Branch() string

func (Revision) Commit

func (r Revision) Commit() string

func (Revision) IsUnknown

func (r Revision) IsUnknown() bool

IsUnknown reports whether the revision could not be resolved from git.

type Scan

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

Scan is the aggregate root for one execution of the Cortex engine against a given revision. It owns the lifecycle status, the timestamps, and the (referential) list of findings produced.

Findings are held by Fingerprint, not by value — keeping the Scan aggregate lean and avoiding accidental coupling to Finding internals.

All transition methods return a NEW Scan; the receiver is never mutated.

func New

func New(id ID, revision Revision) Scan

New constructs a Scan in StatusQueued and records a Queued event.

func (Scan) Complete

func (s Scan) Complete(now time.Time, findings []finding.Fingerprint) mo.Result[Scan]

Complete transitions Running → Completed and snapshots the findings' fingerprints. Invalid otherwise.

func (Scan) Duration

func (s Scan) Duration() time.Duration

Duration returns the elapsed time if both timestamps are set.

func (Scan) EndedAt

func (s Scan) EndedAt() time.Time

func (Scan) Events

func (s Scan) Events() []DomainEvent

func (Scan) Fail

func (s Scan) Fail(now time.Time, reason string) mo.Result[Scan]

Fail transitions any non-terminal status → Failed. Invalid from a terminal state.

func (Scan) Failure

func (s Scan) Failure() string

func (Scan) Findings

func (s Scan) Findings() []finding.Fingerprint

func (Scan) ID

func (s Scan) ID() ID

func (Scan) Revision

func (s Scan) Revision() Revision

func (Scan) Start

func (s Scan) Start(now time.Time) mo.Result[Scan]

Start transitions Queued → Running. Invalid otherwise.

func (Scan) StartedAt

func (s Scan) StartedAt() time.Time

func (Scan) Status

func (s Scan) Status() Status

type Started

type Started struct {
	ID ID
	At time.Time
}

Started is recorded on transition Queued → Running.

func (Started) EventName

func (Started) EventName() string

type Status

type Status int

Status represents the lifecycle state of a Scan.

Transitions:

Queued ──Start──▶ Running ──Complete──▶ Completed (terminal)
   │                  │
   └──Fail──▶ Failed (terminal)
                      │
                      └──Fail──▶ Failed (terminal)
const (
	StatusQueued Status = iota
	StatusRunning
	StatusCompleted
	StatusFailed
)

func (Status) IsTerminal

func (s Status) IsTerminal() bool

IsTerminal reports whether the scan has reached an end state.

func (Status) String

func (s Status) String() string

String implements fmt.Stringer.

Jump to

Keyboard shortcuts

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