gomod

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package gomod reads and edits the go.mod of a project through the go command.

go mod edit works offline and keeps the file formatted the way go writes it, which is why it is used instead of editing the text.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTool

func AddTool(dir, module, pkg, version string) error

AddTool declares a tool. The module is required at the given version unless the project already requires it: a version the project chose is kept.

func DropTool

func DropTool(dir, pkg string) error

DropTool removes a tool declaration. The require line stays until go mod tidy finds it unused, which keeps a module the project imports itself.

func Exists

func Exists(dir string) bool

Exists reports whether the project has a go.mod.

Types

type File

type File struct {
	Module   string
	Go       string            // the go directive
	Requires map[string]string // module path to version
	Replaced []string          // module paths with a replace directive
	Tools    []string          // packages declared with tool
}

File is the part of go.mod platformgo cares about.

func Read

func Read(dir string) (File, error)

Read loads go.mod of the project.

func (File) HasTool

func (f File) HasTool(pkg string) bool

HasTool reports whether a package is declared as a tool.

Jump to

Keyboard shortcuts

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