util

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModuleFileName      = "MODULE"
	ModuleSyntaxVersion = 3

	BuildDirName = "BUILD"
	// DepsDirName is directory that dependencies are stored in.
	DepsDirName     = "DEPS"
	WarningFileName = "WARNING.readme.txt"
)

ModuleFileName is the name of the file describing each module.

Variables

View Source
var FlagNoWorkspaceChecks = false

Functions

func CheckWorkspace added in v2.0.2

func CheckWorkspace()

func CopyDirRecursively added in v2.0.2

func CopyDirRecursively(sourceDir, destDir string) error

Copies a directory recursing into its inner directories

func CopyFile

func CopyFile(sourceFile, destFile string)

func CutPrefix added in v2.0.2

func CutPrefix(str string, prefix string) (string, bool)

Reimplementation of CutPrefix for backwards compatibility with versions < 1.20

func DirExists

func DirExists(dir string) bool

DirExists checks whether some directory exists.

func EnsureManagedDir added in v2.0.2

func EnsureManagedDir(dir string)

func FileExists

func FileExists(file string) bool

FileExists checks whether some file exists.

func GenerateFile added in v2.0.2

func GenerateFile(filePath string, tmpl template.Template, args any)

func GetModuleRoot

func GetModuleRoot() string

GetModuleRoot returns the root directory of the current module.

func GetModuleRootForPath

func GetModuleRootForPath(p string) string

func GetWorkingDir

func GetWorkingDir() string

GetWorkingDir returns the current working directory.

func GetWorkspaceRoot

func GetWorkspaceRoot() string

GetWorkspaceRoot returns the root directory of the current workspace (i.e., top-level module).

func MappedSlice added in v2.0.2

func MappedSlice[V any, U any](values []V, f func(V) U) []U

Maps the input slice using the provided mapping function.

func MkdirAll

func MkdirAll(p string)

MkdirAll creates directory `p` and all parent directories.

func OrderedKeys added in v2.0.2

func OrderedKeys[K constraints.Ordered, V any](m map[K]V) []K

Convenience function, returning the list of ordered keys of the input map.

func OrderedSlice added in v2.0.2

func OrderedSlice[V constraints.Ordered](values []V) []V

Returns the ordered copy of the provided slice, the values are shallow-copied.

func OrderedValues added in v2.0.2

func OrderedValues[K constraints.Ordered, V any](m map[K]V) []V

Convenience function, returning the list of values ordered by their keys.

func ReadFile

func ReadFile(filePath string) []byte

func ReadJson

func ReadJson(filePath string, v interface{})

func ReadYaml

func ReadYaml(filePath string, v interface{})

func RemoveDir

func RemoveDir(p string)

RemoveDir removes a directory and all of its content.

func SliceOrderedBy added in v2.0.2

func SliceOrderedBy[V any, K constraints.Ordered](values []V, key func(v *V) K) []V

Returns the ordered copy of the provided slice, ordering is done using the key function.

func Version added in v2.0.2

func Version() string

func VersionTriplet added in v2.0.2

func VersionTriplet() [3]uint
func WalkSymlink(root string, walkFn filepath.WalkFunc) error

WalkSymlink works like filepath.Walk but also accepts symbolic links as `root`.

func WriteFile

func WriteFile(filePath string, data []byte)

func WriteJson

func WriteJson(filePath string, v interface{})

func WriteYaml

func WriteYaml(filePath string, v interface{})

Types

type OrderedMap added in v2.0.2

type OrderedMap[K constraints.Ordered, V any] struct {
	// contains filtered or unexported fields
}

OrderedMap is a map supporting iteration ordered by the key.

In addition, the map aborts on an attempt to override a key. This behavior is configurable, and can be turned off.

func NewOrderedMap added in v2.0.2

func NewOrderedMap[K constraints.Ordered, V any]() OrderedMap[K, V]

Instantiates an empty OrderedMap object.

func NewOrderedMapFrom added in v2.0.2

func NewOrderedMapFrom[K constraints.Ordered, V any](raw map[K]V) OrderedMap[K, V]

Instantiates a new OrderedMap from a given conventional map by shallow-copying both the keys and the values.

func (*OrderedMap[K, V]) AllowOverrides added in v2.0.2

func (m *OrderedMap[K, V]) AllowOverrides()

Allow key overrides of the keys.

func (*OrderedMap[K, V]) Entries added in v2.0.2

func (m *OrderedMap[K, V]) Entries() []OrderedMapEntry[K, V]

Returns the list of entries ordered by keys.

func (*OrderedMap[K, V]) Get added in v2.0.2

func (m *OrderedMap[K, V]) Get(key K) V

Performs a lookup of the key, and aborts if the key is not found.

func (*OrderedMap[K, V]) Insert added in v2.0.2

func (m *OrderedMap[K, V]) Insert(key K, value V)

Insert a (key, value) pair.

func (*OrderedMap[K, V]) Keys added in v2.0.2

func (m *OrderedMap[K, V]) Keys() []K

Returns the ordered list of map keys.

func (*OrderedMap[K, V]) Lookup added in v2.0.2

func (m *OrderedMap[K, V]) Lookup(key K) (V, bool)

Performs a lookup of the key, similar to `v, ok := m[k]`.

func (*OrderedMap[K, V]) Values added in v2.0.2

func (m *OrderedMap[K, V]) Values() []V

Returns the values of entries ordered by their keys.

type OrderedMapEntry added in v2.0.2

type OrderedMapEntry[K constraints.Ordered, V any] struct {
	Key   K
	Value V
}

OrderedMapEntry is an accessor into a single (key, value) pair of the map.

func OrderedEntries added in v2.0.2

func OrderedEntries[K constraints.Ordered, V any](m map[K]V) []OrderedMapEntry[K, V]

Convenience function, returning the list of ordered entries of the input map.

Jump to

Keyboard shortcuts

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