gomod

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 15, 2022 License: MIT Imports: 16 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 WithFSCache

func WithFSCache(cache *fscache.Cache) func(o *option)

WithFileCache uses a file cache

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(oldPath, newPath string) error

func (*File) Replaces

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

Return a list of replaces

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 Parse

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

Parse a modfile from it's data

func (*Module) DirFS

func (m *Module) DirFS(subpaths ...string) vfs.ReadWritable

DirFS returns an OS filesystem you can read and write from. TODO: remove vfs.ReadWritable

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) 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) 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) 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)

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