goutil

package
v1.22.2 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package goutil provides shared utility functions used across multiple internal packages (analyze, explore, compare, codegraph).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assert

func Assert(cond bool, msg string)

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 Assertf

func Assertf(cond bool, format string, args ...any)

Assertf panics with a formatted message if cond is false.

func CountLines

func CountLines(source []byte) int

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

func IsStdlibImport(path string) bool

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

func PackageDir(root, filePath string) string

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

func RunDAG[T DAGNode](ctx context.Context, nodes []T, workers int, fn func(T) error) error

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

func SortedSetKeys(m map[string]struct{}) []string

SortedSetKeys returns sorted keys of a set (map[string]struct{}).

Types

type DAGNode

type DAGNode interface {
	// NodeID returns the unique identifier for this node.
	NodeID() string
	// NodeDeps returns IDs of nodes that must complete before this one.
	NodeDeps() []string
}

DAGNode is implemented by any item that knows its ID and dependencies.

Jump to

Keyboard shortcuts

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