gomod

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCantInfer = errors.New("mod: unable to infer the module path")

ErrCantInfer occurs when you can't infer the module path from the $GOPATH.

View Source
var ErrFileNotFound = fmt.Errorf("unable to find go.mod: %w", fs.ErrNotExist)

ErrFileNotFound occurs when no go.mod can be found

Functions

func Absolute

func Absolute(dir string) (abs string, err error)

Absolute traverses up the filesystem until it finds a directory containing go.mod or returns an error trying.

func Infer

func Infer(dir string) string

Infer the module path from the $GOPATH. This only works if you work inside $GOPATH.

func WithModCache

func WithModCache(cache *modcache.Cache) func(o *option)

WithModCache uses a custom mod cache instead of the default

Types

type File

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

func (*File) AddReplace

func (f *File) AddReplace(oldPath, oldVers, newPath, newVers string) error

func (*File) AddRequire

func (f *File) AddRequire(importPath, version string) error

func (*File) Format

func (f *File) Format() []byte

func (*File) Import

func (f *File) Import(subPaths ...string) string

Import returns the module's import path (e.g. github.com/livebud/bud)

func (*File) Replace

func (f *File) Replace(path string) *module.Version

Replace finds a replaced package within go.mod or returns nil if not found.

func (*File) Replaces

func (f *File) Replaces() (reps []*Replace)

Return a list of replaces

func (*File) Require added in v0.1.4

func (f *File) Require(path string) *module.Version

Require finds a required package within go.mod

func (*File) Requires

func (f *File) Requires() (reqs []*Require)

Return a list of requires

type Module

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

func Find

func Find(dir string, options ...Option) (*Module, error)

func FindBudModule added in v0.2.6

func FindBudModule() (*Module, error)

FindBudModule finds the go.mod for bud itself

func New added in v0.2.6

func New(dir string, options ...Option) *Module

func Parse

func Parse(path string, data []byte, options ...Option) (*Module, error)

Parse a modfile from it's data

func (*Module) Directory

func (m *Module) Directory(subpaths ...string) string

Directory returns the module directory (e.g. /Users/$USER/...)

func (*Module) File

func (m *Module) File() *File

Get go.mod

func (*Module) Find

func (m *Module) Find(importPath string) (*Module, error)

Find a dependency from an import path

func (*Module) FindBy added in v0.2.4

func (m *Module) FindBy(match func(req *Require) bool) (modules []*Module, err error)

func (*Module) FindIn

func (m *Module) FindIn(fsys fs.FS, importPath string) (*Module, error)

Find a dependency from an import path within fsys Note: go.mod itself needs to really be in the filesystem

func (*Module) Hash

func (m *Module) Hash() []byte

Hash the module

func (*Module) Import

func (m *Module) Import(subpaths ...string) string

Import returns the module's import path (e.g. github.com/livebud/bud)

func (*Module) IsLocal

func (m *Module) IsLocal(importPath string) bool

IsLocal returns true if the import path is within the module

func (*Module) MkdirAll added in v0.2.5

func (m *Module) MkdirAll(path string, perm fs.FileMode) error

MkdirAll creates dir within the module dir. Used to implement virtual.FS

func (*Module) ModCache

func (m *Module) ModCache() string

ModCache returns the module cache directory

func (*Module) Open

func (m *Module) Open(name string) (fs.File, error)

Open a file within the module

func (*Module) ReadDir added in v0.0.2

func (m *Module) ReadDir(name string) ([]fs.DirEntry, error)

func (*Module) RemoveAll added in v0.2.5

func (m *Module) RemoveAll(path string) error

RemoveAll removes a file within the module dir. Used to implement virtual.FS.

func (*Module) ResolveDirectory

func (m *Module) ResolveDirectory(importPath string) (directory string, err error)

ResolveDirectory resolves an import to an absolute path

func (*Module) ResolveDirectoryIn

func (m *Module) ResolveDirectoryIn(localFS fs.FS, importPath string) (directory string, err error)

ResolveDirectory resolves an import to an absolute path. LocalFS maybe used if we're resolving an import path from within the current modules filesystem.

func (*Module) ResolveImport

func (m *Module) ResolveImport(directory string) (importPath string, err error)

ResolveImport returns an import path from a local directory.

func (*Module) Stat added in v0.0.2

func (m *Module) Stat(name string) (fs.FileInfo, error)

func (*Module) Sub added in v0.2.5

func (m *Module) Sub(dir string) (virtual.FS, error)

RemoveAll removes a file within the module dir. Used to implement virtual.FS.

func (*Module) WriteFile added in v0.2.5

func (m *Module) WriteFile(name string, data []byte, perm fs.FileMode) error

WriteFile writes a file within the module dir. Used to implement virtual.FS.

type Option

type Option = func(o *option)

type Replace

type Replace = modfile.Replace

type Require

type Require = modfile.Require

type Version

type Version = module.Version

Jump to

Keyboard shortcuts

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