util

package
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 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

func CheckWorkspace()

func CopyDirRecursively

func CopyDirRecursively(sourceDir, destDir string) error

Copies a directory recursing into its inner directories

func CopyFile

func CopyFile(sourceFile, destFile string)

func CutPrefix

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

func EnsureManagedDir(dir string)

func FileExists

func FileExists(file string) bool

FileExists checks whether some file exists.

func GenerateFile

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

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

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

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

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

func OrderedValues

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

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

func Version() string

func VersionTriplet

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

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

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

Instantiates an empty OrderedMap object.

func NewOrderedMapFrom

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

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

Allow key overrides of the keys.

func (*OrderedMap[K, V]) Entries

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

Returns the list of entries ordered by keys.

func (*OrderedMap[K, V]) Get

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

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

Insert a (key, value) pair.

func (*OrderedMap[K, V]) Keys

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

Returns the ordered list of map keys.

func (*OrderedMap[K, V]) Lookup

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

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

Returns the values of entries ordered by their keys.

type OrderedMapEntry

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

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