Documentation
¶
Overview ¶
Package codebase builds a Codebase, a read-only view of one codebase, over a CodebaseSource: file selection, contents, pattern matches, the Go and YAML parsed forms and rendered charts. Every view is memoized on a Snapshot, so concurrent checks share one listing, one read and one parse of each file and one render of each chart for a run.
Index ¶
- func Decode(format, name string, src []byte) (any, error)
- func GeneratedHeader(src []byte) bool
- func GeneratedName(p string) bool
- func Glob(pattern, p string) bool
- func Matches(sel types.FileSelector, p string) bool
- func New(src interfaces.CodebaseSource, snap *Snapshot, renderer interfaces.Renderer) interfaces.Codebase
- type Snapshot
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶ added in v0.0.20
Decode decodes src, named name for errors, in format ("yaml", "hcl" or "alloy") into the Document shape: the first YAML document, or the one HCL / Alloy document. It serves configuration embedded in another file (an Alloy config inside a Helm values string). An unknown format or a parse error is CodeInvalidInput.
func GeneratedHeader ¶
GeneratedHeader reports whether Go source carries the standard generated-code marker, a `// Code generated … DO NOT EDIT.` line before the package clause.
func GeneratedName ¶
GeneratedName reports whether a Go file's name marks it generated: protobuf and gRPC output, `_gen.go` / `.gen.go` files, `zz_generated` deep-copy files and `mock_*.go` mocks.
func Glob ¶
Glob reports whether the slash-separated path p matches pattern, where `**` matches any number of whole segments (including none) and every other segment matches as path.Match does. A malformed segment matches nothing.
func Matches ¶
func Matches(sel types.FileSelector, p string) bool
Matches reports whether sel selects path on its path alone: Roots, Paths, Globs, Exts and Exclude (TrackedOnly, IncludeGenerated and IncludeIgnored need the file, not its path).
func New ¶
func New( src interfaces.CodebaseSource, snap *Snapshot, renderer interfaces.Renderer, ) interfaces.Codebase
New returns the Codebase over src, memoized on snap; renderer may be nil.
Types ¶
type Snapshot ¶
type Snapshot struct {
// contains filtered or unexported fields
}
Snapshot memoizes a run's views of one repository: every keyed value is computed once and shared by concurrent callers for the snapshot's life. A Snapshot is safe for concurrent use; construct it with NewSnapshot.
func NewSnapshot ¶
NewSnapshot returns an empty snapshot identified by key.
func (*Snapshot) Keys ¶ added in v0.0.20
Keys returns the memo keys the snapshot holds, sorted: every build that finished with a value or a stored error (a cancelled or panicking build leaves no key). It is the record of what a run computed, so a test can assert a view was built once.
func (*Snapshot) Memo ¶
func (s *Snapshot) Memo[T any]( ctx context.Context, key string, build func(context.Context) (T, error), ) (T, error)
Memo returns the value build computes for key, running build once per key: callers that arrive while it runs wait for it (or for their own ctx), and later callers get the stored value. A build error is stored and returned to every caller, except a context cancellation or deadline, which is returned to its caller only so the next caller builds afresh. A build that panics is CodeInternal for its caller and the callers waiting on it, and is not stored, so a later caller builds again. A key reused with a different T is CodeInternal.