resolve

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package resolve turns raw import strings into absolute file paths.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GoModResolver

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

GoModResolver resolves Go module-internal imports using go.mod. It expands package imports to the individual .go files in the directory.

func NewGoModResolver

func NewGoModResolver(rootDir string) (*GoModResolver, error)

NewGoModResolver creates a resolver that uses go.mod for module path resolution.

func (*GoModResolver) Resolve

func (r *GoModResolver) Resolve(importPath, fromFile, rootDir string) ([]string, error)

type RelativeResolver

type RelativeResolver struct {
	Extensions []string
}

RelativeResolver resolves relative imports (./foo, ../bar) by trying various file extensions.

func NewRelativeResolver

func NewRelativeResolver(extensions []string) *RelativeResolver

NewRelativeResolver creates a resolver for relative imports.

func (*RelativeResolver) Resolve

func (r *RelativeResolver) Resolve(importPath, fromFile, rootDir string) ([]string, error)

type Resolver

type Resolver interface {
	// Resolve attempts to resolve importPath to absolute file path(s).
	// fromFile is the absolute path of the importing file.
	// rootDir is the project root.
	// Returns nil if the import cannot be resolved (e.g., external package).
	Resolve(importPath string, fromFile string, rootDir string) ([]string, error)
}

Resolver turns raw import strings into absolute file paths.

func DefaultResolver

func DefaultResolver(rootDir string, extensions []string) Resolver

DefaultResolver returns a resolver chain suitable for most projects. extensions should be the set of file extensions the project's parsers handle.

func Multi

func Multi(resolvers ...Resolver) Resolver

Multi chains resolvers, returning the first successful resolution.

Jump to

Keyboard shortcuts

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