util

package
v0.0.0-...-f342e06 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2018 License: GPL-3.0 Imports: 13 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 Code

func Code(code string) string

Code takes a code block as a backtick enclosed `heredoc` and removes any common indentation from each line. This helps inline code as strings to be formatted nicely without unnecessary indentation. It also drops the very first line of code if it has zero length.

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 ExpandHome

func ExpandHome(p string) (string, error)

ExpandHome does an expansion of ~/ or ~james/ into user's home dir value.

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 SortedStrSliceCompare

func SortedStrSliceCompare(a, b []string) error

SortedStrSliceCompare takes two lists of strings and returns whether or not they are equivalent. It will return nil if both sets contain the same elements, regardless of order, and an error if they do not.

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

type EasyExit

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

EasyExit is a struct that helps you build a close switch and signal which can be called multiple times safely, and used as a signal many times in parallel.

func NewEasyExit

func NewEasyExit() *EasyExit

NewEasyExit builds an easy exit struct.

func (*EasyExit) Done

func (obj *EasyExit) Done(err error)

Done triggers the exit signal. It associates an error condition with it too.

func (*EasyExit) Error

func (obj *EasyExit) Error() error

Error returns the error condition associated with the Done signal. It blocks until Done is called at least once. It then returns any of the errors or nil. It is only guaranteed to at least return the error from the first Done error.

func (*EasyExit) Signal

func (obj *EasyExit) Signal() chan struct{}

Signal returns the channel that we watch for the exit signal on. It will close to signal us when triggered by Exit().

type EasyOnce

type EasyOnce struct {
	Func func()
	// contains filtered or unexported fields
}

EasyOnce is a wrapper for the sync.Once functionality which lets you define and register the associated `run once` function at declaration time. It may be copied at any time.

func (*EasyOnce) Done

func (obj *EasyOnce) Done()

Done runs the function which was defined in `Func` a maximum of once.

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