mod

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package mod allows programmatic editions of Go mod file. It wraps `golang.org/x/mod` with easier to use API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExcludeDirective

type ExcludeDirective struct {
	Module module.Version
}

type File

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

File represents .mod file for Go Module use.

func OpenFile

func OpenFile(modFile string) (_ *File, err error)

OpenFile opens mod file for edits in place. It's a caller responsibility to Close the file when not using anymore.

func (*File) AddComment

func (mf *File) AddComment(comment string) error

func (*File) Close

func (mf *File) Close() error

Close closes file. TODO(bwplotka): Ensure other methods will return error on use after Close.

func (*File) Comments

func (mf *File) Comments() (comments []string)

func (*File) ExcludeDirectives

func (mf *File) ExcludeDirectives() []ExcludeDirective

func (*File) Filepath

func (mf *File) Filepath() string

func (*File) GoVersion

func (mf *File) GoVersion() string

func (*File) Module

func (mf *File) Module() (path string, comment string)

func (*File) Reload

func (mf *File) Reload() (err error)

Reload re-parses module file from the latest state on the disk.

func (*File) ReplaceDirectives

func (mf *File) ReplaceDirectives() []ReplaceDirective

func (*File) RequireDirectives

func (mf *File) RequireDirectives() []RequireDirective

func (*File) RetractDirectives

func (mf *File) RetractDirectives() []RetractDirective

func (*File) SetExcludeDirectives

func (mf *File) SetExcludeDirectives(directives ...ExcludeDirective) (err error)

SetExcludeDirectives removes all replace statements and set to the given ones.

func (*File) SetGoVersion

func (mf *File) SetGoVersion(version string) error

func (*File) SetModule

func (mf *File) SetModule(path string, comment string) error

func (*File) SetReplaceDirectives

func (mf *File) SetReplaceDirectives(directives ...ReplaceDirective) (err error)

SetReplaceDirectives removes all replace statements and set to the given ones.

func (*File) SetRequireDirectives

func (mf *File) SetRequireDirectives(directives ...RequireDirective) (err error)

SetRequireDirectives removes all require statements and set to the given ones.

func (*File) SetRetractDirectives

func (mf *File) SetRetractDirectives(directives ...RetractDirective) (err error)

SetRetractDirectives removes all replace statements and set to the given ones.

type FileForRead

type FileForRead interface {
	Reload() error
	Filepath() string

	Module() (path string, comment string)
	Comments() (comments []string)
	GoVersion() string
	RequireDirectives() []RequireDirective
	ReplaceDirectives() []ReplaceDirective
	ExcludeDirectives() []ExcludeDirective
	RetractDirectives() []RetractDirective

	Close() error
}

func OpenFileForRead

func OpenFileForRead(modFile string) (_ FileForRead, err error)

OpenFileForRead opens mod file for reads. It's a caller responsibility to Close the file when not using anymore.

type ReplaceDirective

type ReplaceDirective struct {
	Old module.Version
	New module.Version
}

type RequireDirective

type RequireDirective struct {
	Module   module.Version
	Indirect bool

	// ExtraSuffixComment represents comment (without '// ') after potential indirect comment
	// that can contain additional information.
	ExtraSuffixComment string
}

type RetractDirective

type RetractDirective struct {
	VersionInterval
	Rationale string
}

type VersionInterval

type VersionInterval = modfile.VersionInterval

Jump to

Keyboard shortcuts

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