Documentation
¶
Overview ¶
Package goutil provides shared utility functions used across multiple internal packages (analyze, explore, compare, codegraph).
Index ¶
- func Assert(cond bool, msg string)
- func Assertf(cond bool, format string, args ...any)
- func CountLines(source []byte) int
- func Fail(msg string)
- func IsStdlibImport(path string) bool
- func PackageDir(root, filePath string) string
- func RunDAG[T DAGNode](ctx context.Context, nodes []T, workers int, fn func(T) error) error
- func SortedSetKeys(m map[string]struct{}) []string
- type DAGNode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Assert ¶
Assert panics with msg if cond is false. Use for internal invariants that must never be violated by correct code. Prefer returning errors for recoverable conditions; use Assert only for logic bugs where the program state is corrupt and continuing is unsafe.
func CountLines ¶
CountLines returns the number of lines in source. A trailing newline does not count as an extra line. Returns 0 for empty input.
func Fail ¶
func Fail(msg string)
Fail unconditionally panics. Use in unreachable branches (e.g. exhaustive switch default cases) to make the invariant explicit and produce a useful stack trace instead of a silent nil-deref.
func IsStdlibImport ¶
IsStdlibImport reports whether an import path looks like a Go stdlib package. Stdlib paths have no dots in the first segment (e.g. "fmt", "net/http").
func PackageDir ¶
PackageDir returns the directory portion of filePath relative to root. If the relative dir is ".", it falls back to filepath.Base(root). This matches the convention used for package-level import graphs.
func RunDAG ¶
RunDAG executes nodes in dependency order using a worker pool. Nodes whose dependencies are all done become "ready" and are dispatched to workers immediately — this mirrors the findAllRunnable pattern from go-workflow/engine_dag.go.
fn is called once per node; the first error aborts remaining work. workers <= 0 defaults to runtime.NumCPU().
func SortedSetKeys ¶
SortedSetKeys returns sorted keys of a set (map[string]struct{}).