gomod

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, command string, modfile string, stdout io.Writer, args ...string) error

Run executes the `go mod <command> <args...>` subcommand with the provided arguments on the designated `go.mod` file, sending standard output to the provided writer.

func RunEdit

func RunEdit(ctx context.Context, modfile string, edits ...Edit) error

RunEdit makes the specified changes to the `go.mod` file, then runs `go mod tidy` if needed. If there is a `vendor` directory, it also runs `go mod vendor` before returning.

func RunGet

func RunGet(ctx context.Context, modfile string, modSpecs ...string) error

RunGet executes the `go get <modSpecs...>` subcommand with the provided module specifications on the designated `go.mod` file.

Types

type Edit

type Edit interface {
	// contains filtered or unexported methods
}

Edit represents an edition that can be made to a `go.mod` file via `go mod edit`.

type File

type File struct {
	// Go is the value of the `go` directive.
	Go Version
	// Toolchain is the value of the `toolchain` directive, if present.
	Toolchain Toolchain
	// Require is a list of all `require` directives' contents.
	Require []Require
}

File represents some selected entries from the content of a `go.mod` file.

func Parse

func Parse(ctx context.Context, modfile string) (File, error)

Parse processes the contents of the designated `go.mod` file using `go mod edit -json` and returns the corresponding parsed [goMod].

func (*File) Requires

func (m *File) Requires(path string) (string, bool)

Requires returns true if the `go.mod` file contains a require directive for the designated module path.

type Replace

type Replace struct {
	// OldPath is the path of the module being replaced.
	OldPath string
	// OldVersion is the version of the module being replaced, if any.
	OldVersion string
	// NewPath is the path of the replacement module.
	NewPath string
	// NewVersion is the version of the replacement module, if any.
	NewVersion string
}

Replace represents the target of a `replace` directive entry.

type Require

type Require struct {
	// Path is the path of the required module.
	Path string
	// Version is the required module's version.
	Version string
}

Require represents the target of a `require` directive entry.

type Toolchain

type Toolchain string

type Version

type Version string

Jump to

Keyboard shortcuts

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