util

package
v0.0.0-...-173ccf6 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2018 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package util contains a collection of miscellaneous utility functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Basename

func Basename(p string) string

Basename is the base of a path string.

func Bool

func Bool(x interface{}) bool

Bool returns the interface value if it is a bool, and otherwise it panics.

func BoolMapTrue

func BoolMapTrue(l []bool) bool

BoolMapTrue returns true if everyone in the list is true.

func BoolMapValues

func BoolMapValues(m map[string]bool) []bool

BoolMapValues returns the sorted list of bool values in a map with string values.

func CopyDiskToFs

func CopyDiskToFs(dstFs afero.Fs, src, dst string, force bool) error

CopyDiskToFs performs exactly as CopyFs, except that the src fs is our local disk os fs.

func CopyFs

func CopyFs(srcFs, dstFs afero.Fs, src, dst string, force bool) error

CopyFs copies a dir from the srcFs to a dir on the dstFs. It expects that the dst will be either empty, or that the force flag will be set to true. If the dst has a different set of contents in the same location, the behaviour is currently undefined. TODO: this should be made more rsync like and robust!

func CopyFsToDisk

func CopyFsToDisk(srcFs afero.Fs, src, dst string, force bool) error

CopyFsToDisk performs exactly as CopyFs, except that the dst fs is our local disk os fs.

func DirifyFileList

func DirifyFileList(fileList []string, removeDirs bool) []string

DirifyFileList adds trailing slashes to any likely dirs in a package manager fileList if removeDirs is true, otherwise, don't keep the dirs in our output.

func Dirname

func Dirname(p string) string

Dirname is similar to the GNU dirname command.

func FirstToUpper

func FirstToUpper(str string) string

FirstToUpper returns the string with the first character capitalized.

func FlattenListWithSplit

func FlattenListWithSplit(input []string, split []string) []string

FlattenListWithSplit flattens a list of input by splitting each element by any and all of the strings listed in the split array

func FsTree

func FsTree(fs afero.Fs, name string) (string, error)

FsTree returns a string representation of the file system tree similar to the well-known `tree` command.

func HasPathPrefix

func HasPathPrefix(p, prefix string) bool

HasPathPrefix tells us if a path string contain the given path prefix in it.

func NumToAlpha

func NumToAlpha(idx int) string

NumToAlpha returns a lower case string of letters representing a number. If you specify 0, you'll get `a`, 25 gives you `z`, and 26 gives you `aa` and so on...

func PathPrefixDelta

func PathPrefixDelta(p, prefix string) int

PathPrefixDelta returns the delta of the path prefix, which tells you how many path tokens different the prefix is.

func PathSplit

func PathSplit(p string) []string

PathSplit splits a path into an array of tokens excluding any trailing empty tokens.

func PathSplitFullReversed

func PathSplitFullReversed(p string) []string

PathSplitFullReversed returns the full list of "dependency" paths for a given path in reverse order.

func RemoveCommonFilePrefixes

func RemoveCommonFilePrefixes(paths []string) []string

RemoveCommonFilePrefixes removes redundant file path prefixes that are under the tree of other files.

func ReverseStringList

func ReverseStringList(in []string) []string

ReverseStringList reverses a list of strings.

func StrFilterElementsInList

func StrFilterElementsInList(filter []string, list []string) []string

StrFilterElementsInList removes any of the elements in filter, if they exist in the list.

func StrInList

func StrInList(needle string, haystack []string) bool

StrInList returns true if a string exists inside a list, otherwise false.

func StrInPathPrefixList

func StrInPathPrefixList(needle string, haystack []string) bool

StrInPathPrefixList returns true if the needle is a PathPrefix in the haystack.

func StrListIntersection

func StrListIntersection(list1 []string, list2 []string) []string

StrListIntersection removes any of the elements in filter, if they don't exist in the list. This is an in order intersection of two lists.

func StrMapKeys

func StrMapKeys(m map[string]string) []string

StrMapKeys return the sorted list of string keys in a map with string keys. NOTE: i thought it would be nice for this to use: map[string]interface{} but it turns out that's not allowed. I know we don't have generics, but come on!

func StrMapKeysUint64

func StrMapKeysUint64(m map[string]uint64) []string

StrMapKeysUint64 return the sorted list of string keys in a map with string keys but uint64 values.

func StrMapValues

func StrMapValues(m map[string]string) []string

StrMapValues returns the sorted list of string values in a map with string values.

func StrMapValuesUint64

func StrMapValuesUint64(m map[uint64]string) []string

StrMapValuesUint64 return the sorted list of string values in a map with string values.

func StrRemoveDuplicatesInList

func StrRemoveDuplicatesInList(list []string) []string

StrRemoveDuplicatesInList removes any duplicate values in the list. This implementation is possibly sub-optimal (O(n^2)?) but preserves ordering.

func SystemBusPrivateUsable

func SystemBusPrivateUsable() (conn *dbus.Conn, err error)

SystemBusPrivateUsable makes using the private bus usable TODO: should be upstream: https://github.com/godbus/dbus/issues/15

func TimeAfterOrBlock

func TimeAfterOrBlock(t int) <-chan time.Time

TimeAfterOrBlock is aspecial version of time.After that blocks when given a negative integer. When used in a case statement, the timer restarts on each select call to it.

func Uint

func Uint(x interface{}) uint

Uint returns the interface value if it is a uint, and otherwise it panics.

func Uint64KeyFromStrInMap

func Uint64KeyFromStrInMap(needle string, haystack map[uint64]string) (uint64, bool)

Uint64KeyFromStrInMap returns true if needle is found in haystack of keys that have uint64 type.

Types

This section is empty.

Directories

Path Synopsis
Package semaphore contains an implementation of a counting semaphore.
Package semaphore contains an implementation of a counting semaphore.

Jump to

Keyboard shortcuts

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