codebase

package
v0.0.39 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 27 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode added in v0.0.20

func Decode(format, name string, src []byte) (any, error)

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

func GeneratedHeader(src []byte) bool

GeneratedHeader reports whether Go source carries the standard generated-code marker, a `// Code generated … DO NOT EDIT.` line before the package clause.

func GeneratedName

func GeneratedName(p string) bool

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

func Glob(pattern, p string) bool

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

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

func NewSnapshot(key string) *Snapshot

NewSnapshot returns an empty snapshot identified by key.

func (*Snapshot) Key

func (s *Snapshot) Key() string

Key returns the snapshot's identity.

func (*Snapshot) Keys added in v0.0.20

func (s *Snapshot) Keys() []string

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.

Jump to

Keyboard shortcuts

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