golang

package
v0.29.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnalyzeGoFileFromContent added in v0.18.0

func AnalyzeGoFileFromContent(filePath string, content []byte) ([]GoImport, []GoEmbed, *GoSymbolInfo, *GoExportInfo, error)

AnalyzeGoFileFromContent parses a Go file once and extracts import paths, embed directives, symbol metadata, and export/import-usage metadata.

func BuildGoPackageExportIndices

func BuildGoPackageExportIndices(dirToFiles map[string][]string, contentReader vcs.ContentReader) map[string]GoPackageExportIndex

func BuildIntraPackageDependencies

func BuildIntraPackageDependencies(filePaths []string, contentReader vcs.ContentReader) (map[string][]string, error)

BuildIntraPackageDependencies builds dependencies between files in the same Go package. The contentReader function is used to read file contents, allowing the caller to control whether files are read from the filesystem, a git commit, or another source.

func BuildIntraPackageDependenciesWithSymbolLookup added in v0.18.0

func BuildIntraPackageDependenciesWithSymbolLookup(
	filePaths []string,
	contentReader vcs.ContentReader,
	symbolLookup func(filePath string) (*GoSymbolInfo, bool),
) (map[string][]string, error)

BuildIntraPackageDependenciesWithSymbolLookup builds dependencies between files in the same Go package and optionally reuses caller-provided symbol metadata.

func GetUsedSymbolsFromPackage

func GetUsedSymbolsFromPackage(exportInfo *GoExportInfo, importPath string) map[string]bool

GetUsedSymbolsFromPackage extracts which symbols from a specific import path are actually used

func IsTestFile

func IsTestFile(filePath string) bool

IsTestFile reports whether the given Go file path is a test file.

func ResolveGoProjectImports

func ResolveGoProjectImports(
	absPath string,
	filePath string,
	dirToFiles map[string][]string,
	goPackageExportIndices map[string]GoPackageExportIndex,
	suppliedFiles map[string]bool,
	contentReader vcs.ContentReader,
) ([]string, error)

Types

type ExternalImport

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

ExternalImport represents an external module import

func (ExternalImport) Path

func (e ExternalImport) Path() string

type GoEmbed

type GoEmbed struct {
	Pattern string // The embed pattern (file path or glob)
}

GoEmbed represents an embedded file from a //go:embed directive

func ParseGoEmbeds

func ParseGoEmbeds(sourceCode []byte) ([]GoEmbed, error)

ParseGoEmbeds parses Go source code and extracts //go:embed directives

type GoExportInfo

type GoExportInfo struct {
	FilePath      string
	Package       string
	Exports       map[string]bool            // Exported symbols (capitalized) defined in this file
	ImportAliases map[string]string          // Maps import path to alias used (or package name if no alias)
	DotImports    map[string]bool            // Tracks import paths imported via dot import
	QualifiedRefs map[string]map[string]bool // Maps package alias -> set of symbols accessed
	UnqualRefs    map[string]bool            // Unqualified refs, used for dot-import symbol filtering
}

GoExportInfo tracks exported symbols and import usage in a Go file

func ExtractGoExportInfo

func ExtractGoExportInfo(filePath string) (*GoExportInfo, error)

ExtractGoExportInfo analyzes a Go file and extracts exported symbols and import usage

func ExtractGoExportInfoFromContent

func ExtractGoExportInfoFromContent(filePath string, content []byte) (*GoExportInfo, error)

ExtractGoExportInfoFromContent analyzes Go source code and extracts exported symbols and import usage

type GoFileAnalysis added in v0.18.0

type GoFileAnalysis struct {
	Imports    []GoImport
	Embeds     []GoEmbed
	SymbolInfo *GoSymbolInfo
	ExportInfo *GoExportInfo
}

GoFileAnalysis holds all parse-derived metadata for a Go file.

func AnalyzeGoFileDetailsFromContent added in v0.18.0

func AnalyzeGoFileDetailsFromContent(filePath string, content []byte) (*GoFileAnalysis, error)

AnalyzeGoFileDetailsFromContent parses a Go file once and returns a reusable analysis.

type GoImport

type GoImport interface {
	Path() string
}

GoImport represents an import in a Go file

func GoImports

func GoImports(filePath string) ([]GoImport, error)

GoImports parses a Go file and returns its imports

func ParseGoImports

func ParseGoImports(sourceCode []byte) ([]GoImport, error)

ParseGoImports parses Go source code and extracts imports

type GoPackageExportIndex

type GoPackageExportIndex map[string][]string // symbol name -> list of files defining it

GoPackageExportIndex maps exported symbols to their defining files within a package directory

func BuildPackageExportIndex

func BuildPackageExportIndex(filePaths []string, contentReader vcs.ContentReader) (GoPackageExportIndex, error)

BuildPackageExportIndex builds an index of exported symbols for files in a package directory. The contentReader function is used to read file contents, allowing the caller to control whether files are read from the filesystem, a git commit, or another source.

type GoSymbolInfo

type GoSymbolInfo struct {
	FilePath        string
	Package         string
	Defined         map[string]bool // Symbols defined in this file
	Referenced      map[string]bool // Symbols referenced in this file
	MethodReceivers map[string]bool // Receiver type names of methods defined here
}

GoSymbolInfo tracks symbols defined and referenced in a Go file

func ExtractGoSymbols

func ExtractGoSymbols(filePath string) (*GoSymbolInfo, error)

ExtractGoSymbols analyzes a Go file and extracts defined and referenced symbols

func ExtractGoSymbolsFromContent

func ExtractGoSymbolsFromContent(filePath string, content []byte) (*GoSymbolInfo, error)

ExtractGoSymbolsFromContent analyzes Go source code and extracts defined and referenced symbols

type InternalImport

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

InternalImport represents an internal project import

func (InternalImport) Path

func (i InternalImport) Path() string

type ProjectImportResolver

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

ProjectImportResolver encapsulates Go-specific dependency resolution caches and logic.

func NewProjectImportResolver

func NewProjectImportResolver(
	dirToFiles map[string][]string,
	suppliedFiles map[string]bool,
	contentReader vcs.ContentReader,
) *ProjectImportResolver

NewProjectImportResolver creates a Go dependency resolver with precomputed package export indices.

func (*ProjectImportResolver) ResolveProjectImports

func (r *ProjectImportResolver) ResolveProjectImports(absPath, filePath string) ([]string, error)

ResolveProjectImports resolves Go project imports for a single file using cached indices.

type Provider added in v0.27.0

type Provider struct{}

func (Provider) Extensions added in v0.27.0

func (Provider) Extensions() []string

func (Provider) IsTestFile added in v0.27.0

func (Provider) IsTestFile(filePath string, _ vcs.ContentReader) bool

func (Provider) Maturity added in v0.27.0

func (Provider) Maturity() moduleapi.MaturityLevel

func (Provider) Name added in v0.27.0

func (Provider) Name() string

func (Provider) NewResolver added in v0.27.0

func (Provider) NewResolver(ctx *moduleapi.Context, contentReader vcs.ContentReader) moduleapi.Resolver

type StandardLibraryImport

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

StandardLibraryImport represents a Go standard library import

func (StandardLibraryImport) Path

func (s StandardLibraryImport) Path() string

Jump to

Keyboard shortcuts

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