Documentation
¶
Overview ¶
Package mod allows programmatic editions of Go mod file. It wraps `golang.org/x/mod` with easier to use API.
Index ¶
- type ExcludeDirective
- type File
- func (mf *File) AddComment(comment string) error
- func (mf *File) Close() error
- func (mf *File) Comments() (comments []string)
- func (mf *File) ExcludeDirectives() []ExcludeDirective
- func (mf *File) Filepath() string
- func (mf *File) GoVersion() string
- func (mf *File) Module() (path string, comment string)
- func (mf *File) Reload() (err error)
- func (mf *File) ReplaceDirectives() []ReplaceDirective
- func (mf *File) RequireDirectives() []RequireDirective
- func (mf *File) RetractDirectives() []RetractDirective
- func (mf *File) SetExcludeDirectives(directives ...ExcludeDirective) (err error)
- func (mf *File) SetGoVersion(version string) error
- func (mf *File) SetModule(path string, comment string) error
- func (mf *File) SetReplaceDirectives(directives ...ReplaceDirective) (err error)
- func (mf *File) SetRequireDirectives(directives ...RequireDirective) (err error)
- func (mf *File) SetRetractDirectives(directives ...RetractDirective) (err error)
- type FileForRead
- type ReplaceDirective
- type RequireDirective
- type RetractDirective
- type VersionInterval
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ExcludeDirective ¶
type File ¶
type File struct {
// contains filtered or unexported fields
}
File represents .mod file for Go Module use.
func OpenFile ¶
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 (*File) Close ¶
Close closes file. TODO(bwplotka): Ensure other methods will return error on use after Close.
func (*File) ExcludeDirectives ¶
func (mf *File) ExcludeDirectives() []ExcludeDirective
func (*File) GoVersion ¶
GoVersion returns a semver string containing the value of of the go directive. For example, it will return "1.2.3" if the go.mod file contains the line "go 1.2.3". If no go directive is found, it returns "1.0" because: 1. "1.0" is a valid semver string, so it's always safe to parse this value using semver.MustParse(). 2. The semantics of the absence of a go directive in a go.mod file means all versions of Go should be able to compile it.
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 (*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 RequireDirective ¶
type RetractDirective ¶
type RetractDirective struct {
VersionInterval
Rationale string
}
type VersionInterval ¶
type VersionInterval = modfile.VersionInterval