util

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2019 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AreAllStrsInSlice

func AreAllStrsInSlice(queries []string, list []string) bool

func BoolPtr

func BoolPtr(val bool) *bool

func CheckAlphaNumericDashDotUnderscore

func CheckAlphaNumericDashDotUnderscore(s string) bool

func CheckAlphaNumericDashUnderscore

func CheckAlphaNumericDashUnderscore(s string) bool

func CheckDns1035

func CheckDns1035(s string) bool

func CleanURL

func CleanURL(urlStr string) string

func CloseSilent

func CloseSilent(closers ...io.Closer)

func CopyFloat32Slice

func CopyFloat32Slice(vals []float32) []float32

func CopyFloat64Slice

func CopyFloat64Slice(vals []float64) []float64

func CopyInt32Slice

func CopyInt32Slice(vals []int32) []int32

func CopyInt64Slice

func CopyInt64Slice(vals []int64) []int64

func CopyIntSlice

func CopyIntSlice(vals []int) []int

func CopyStrSet

func CopyStrSet(set map[string]bool) map[string]bool

func CopyStrSlice

func CopyStrSlice(vals []string) []string

func CopyTimePtr

func CopyTimePtr(t *time.Time) *time.Time

func CreateDirIfMissing

func CreateDirIfMissing(path string) (bool, error)

func DirPaths

func DirPaths(paths []string, addTrailingSlash bool) []string

func DoStrSetsOverlap

func DoStrSetsOverlap(set1 map[string]bool, set2 map[string]bool) bool

func FileTree

func FileTree(paths []string, cwd string, dirsOrder DirsOrder) string

func FilterStrs

func FilterStrs(strs []string, filterFn func(string) bool) []string

func FindDuplicateStrs

func FindDuplicateStrs(in []string) []string

func FlattenAllStrValues

func FlattenAllStrValues(obj interface{}) ([]string, error)

The order for maps is deterministic

func FlattenAllStrValuesAsSet

func FlattenAllStrValuesAsSet(obj interface{}) (map[string]bool, error)

func Float32Ptr

func Float32Ptr(val float32) *float32

func Float64Ptr

func Float64Ptr(val float64) *float64

func HasDuplicateStr

func HasDuplicateStr(in []string) bool

func HashBytes

func HashBytes(bytes []byte) string

Trim to 63 characters because e.g. K8s labels must be < 64

func HashFile

func HashFile(path string) (string, error)

func HashObj

func HashObj(obj interface{}) string

func HashStr

func HashStr(str string) string

func IgnoreDotFiles

func IgnoreDotFiles(path string, fi os.FileInfo) (bool, error)

func IgnoreNonPython

func IgnoreNonPython(path string, fi os.FileInfo) (bool, error)

func IgnoreNonYAML

func IgnoreNonYAML(path string, fi os.FileInfo) (bool, error)

func IndirectSafe

func IndirectSafe(obj interface{}) interface{}

Dereference if obj is a pointer, otherwise no-op

func Int16Ptr

func Int16Ptr(val int16) *int16

func Int32Ptr

func Int32Ptr(val int32) *int32

func Int64Ptr

func Int64Ptr(val int64) *int64

func Int8Ptr

func Int8Ptr(val int8) *int8

func IntPtr

func IntPtr(val int) *int

func InterfaceMapKeys

func InterfaceMapKeys(myMap map[string]interface{}) []string

func InterfaceMapKeysUnsafe

func InterfaceMapKeysUnsafe(myMap interface{}) []string

func InterfaceMapSortedKeys

func InterfaceMapSortedKeys(myMap map[string]interface{}) []string

func InterfaceMapsKeysMatch

func InterfaceMapsKeysMatch(map1 map[string]interface{}, map2 map[string]interface{}) bool

func IntersectStrSets

func IntersectStrSets(set1 map[string]bool, set2 map[string]bool) map[string]bool

func IsAnyStrInSlice

func IsAnyStrInSlice(queries []string, list []string) bool

func IsDir

func IsDir(path string) bool

func IsFile

func IsFile(path string) bool

func IsFileOrDir

func IsFileOrDir(path string) bool

func IsFilePathPython

func IsFilePathPython(path string) bool

func IsFilePathYAML

func IsFilePathYAML(path string) bool

func IsFloat32InSlice

func IsFloat32InSlice(query float32, list []float32) bool

func IsFloat64InSlice

func IsFloat64InSlice(query float64, list []float64) bool

func IsInt32InSlice

func IsInt32InSlice(query int32, list []int32) bool

func IsInt64InSlice

func IsInt64InSlice(query int64, list []int64) bool

func IsIntInSlice

func IsIntInSlice(query int, list []int) bool

func IsStrInSlice

func IsStrInSlice(query string, list []string) bool

func IsValidS3aPath

func IsValidS3aPath(s3aPath string) bool

func ListDir

func ListDir(dir string, relative bool) ([]string, error)

func ListDirRecursive

func ListDirRecursive(dir string, relative bool, ignoreFns ...IgnoreFn) ([]string, error)

func LocalHourNow

func LocalHourNow() string

func LocalTimestamp

func LocalTimestamp(t *time.Time) string

func LocalTimestampHuman

func LocalTimestampHuman(t *time.Time) string

func MakeEmptyFile

func MakeEmptyFile(path string) error

func MakeEmptyFiles

func MakeEmptyFiles(paths ...string) error

func MakeEmptyFilesInDir

func MakeEmptyFilesInDir(dir string, paths ...string) error

func MapStrs

func MapStrs(strs []string, mapFn func(string) string) []string

func MarshalJSON

func MarshalJSON(obj interface{}) ([]byte, error)

func MarshalJSONStr

func MarshalJSONStr(obj interface{}) (string, error)

func MarshalMsgpack

func MarshalMsgpack(obj interface{}) ([]byte, error)

func MatchAnyRegex

func MatchAnyRegex(s string, regexes []*regexp.Regexp) bool

func MaxInt

func MaxInt(vals ...int) int

func MergeStrMaps

func MergeStrMaps(maps ...map[string]string) map[string]string

func MergeStrSets

func MergeStrSets(sets ...map[string]bool) map[string]bool

func MergeStrSlices

func MergeStrSlices(slices ...[]string) []string

func MicrosecsStr

func MicrosecsStr(t time.Time) string

func MillisecsStr

func MillisecsStr(t time.Time) string

func MinInt

func MinInt(vals ...int) int

func MustMarshalMsgpack

func MustMarshalMsgpack(obj interface{}) []byte

func NowTimestamp

func NowTimestamp() string

func OlderThanSeconds

func OlderThanSeconds(t time.Time, secs float64) bool

func ParentDir

func ParentDir(dir string) string

func Pp

func Pp(obj interface{})

func Ppg

func Ppg(obj interface{})

func Ppj

func Ppj(obj interface{})

func ReadReqFile

func ReadReqFile(r *http.Request, fileName string) ([]byte, error)

Returns nil if no file

func RelPath

func RelPath(userPath string, baseDir string) string

func RemoveEmpties

func RemoveEmpties(strs []string) []string

func RemoveEmptiesAndUnique

func RemoveEmptiesAndUnique(strs []string) []string

func Round

func Round(val float64, decimalPlaces int, pad bool) string

func RunInParallel

func RunInParallel(fns ...func() error) []error

func RunInParallelFirstErr

func RunInParallelFirstErr(fns ...func() error) error

func SearchForFile

func SearchForFile(filename string, dir string) (string, error)

func SortFilePaths

func SortFilePaths(paths []string, dirsOrder DirsOrder) []string

func SortFloat32s

func SortFloat32s(a []float32)

func SortFloat32sCopy

func SortFloat32sCopy(a []float32) []float32

func SortFloat64sCopy

func SortFloat64sCopy(a []float64) []float64

func SortInt32s

func SortInt32s(a []int32)

func SortInt32sCopy

func SortInt32sCopy(a []int32) []int32

func SortInt64s

func SortInt64s(a []int64)

func SortInt64sCopy

func SortInt64sCopy(a []int64) []int64

func SortIntsCopy

func SortIntsCopy(a []int) []int

func SortStrsCopy

func SortStrsCopy(a []string) []string

func SplitS3aPath

func SplitS3aPath(s3aPath string) (string, string, error)

func Sppg

func Sppg(obj interface{}) string

func StrMapKeys

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

func StrMapValues

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

func StrPtr

func StrPtr(val string) *string

func StrSetToSlice

func StrSetToSlice(set map[string]bool) []string

func StrSliceElementsMatch

func StrSliceElementsMatch(strs1 []string, strs2 []string) bool

func StrSliceToSet

func StrSliceToSet(strs []string) map[string]bool

func StrSlicesEqual

func StrSlicesEqual(strs1 []string, strs2 []string) bool

func SubtractStrSets

func SubtractStrSets(set1 map[string]bool, set2 map[string]bool) map[string]bool

func SubtractStrSlice

func SubtractStrSlice(slice1 []string, slice2 []string) []string

func TimeDifference

func TimeDifference(t1 *time.Time, t2 *time.Time) string

func TimeNowPtr

func TimeNowPtr() *time.Time

func TimePtrsEqual

func TimePtrsEqual(t1 *time.Time, t2 *time.Time) bool

func TimeSince

func TimeSince(t *time.Time) string

func Timestamp

func Timestamp(t time.Time) string

func TmpDir

func TmpDir() (string, error)

func TrimDirPrefix

func TrimDirPrefix(fullPath string, dirPath string) string

func URLJoin

func URLJoin(strs ...string) string

func UniqueStrs

func UniqueStrs(strs []string) []string

func UnmarshalMsgpack

func UnmarshalMsgpack(b []byte, obj interface{}) error

func UnmarshalMsgpackToInterface

func UnmarshalMsgpackToInterface(b []byte) (interface{}, error)

func Unzip

func Unzip(src string, destPath string) ([]string, error)

func UnzipFileToMem

func UnzipFileToMem(src string) (map[string][]byte, error)

func UnzipMemToMem

func UnzipMemToMem(zipBytes []byte) (map[string][]byte, error)

func UnzipToMem

func UnzipToMem(r *zip.Reader) (map[string][]byte, error)

func UserPath

func UserPath(userPath string) string

func WriteJSON

func WriteJSON(obj interface{}, outPath string) error

func Zip

func Zip(zipInput *ZipInput, destPath string) error

func ZipStrsToMap

func ZipStrsToMap(strs1 []string, strs2 []string) map[string]string

func ZipToMem

func ZipToMem(zipInput *ZipInput) ([]byte, error)

func ZipToWriter

func ZipToWriter(zipInput *ZipInput, writer io.Writer) error

Types

type DirsOrder

type DirsOrder string
var DirsOnBottom DirsOrder = "bottom"
var DirsOnTop DirsOrder = "top"
var DirsSorted DirsOrder = "sorted"

type Float32Slice

type Float32Slice []float32

func (Float32Slice) Len

func (p Float32Slice) Len() int

func (Float32Slice) Less

func (p Float32Slice) Less(i, j int) bool

func (Float32Slice) Swap

func (p Float32Slice) Swap(i, j int)

type IgnoreFn

type IgnoreFn func(string, os.FileInfo) (bool, error)

If passed a dir, returning false will ignore all subdirs of dir

type Int32Slice

type Int32Slice []int32

func (Int32Slice) Len

func (p Int32Slice) Len() int

func (Int32Slice) Less

func (p Int32Slice) Less(i, j int) bool

func (Int32Slice) Swap

func (p Int32Slice) Swap(i, j int)

type Int64Slice

type Int64Slice []int64

func (Int64Slice) Len

func (p Int64Slice) Len() int

func (Int64Slice) Less

func (p Int64Slice) Less(i, j int) bool

func (Int64Slice) Swap

func (p Int64Slice) Swap(i, j int)

type ZipBytesInput

type ZipBytesInput struct {
	Content []byte
	Dest    string
}

type ZipDirInput

type ZipDirInput struct {
	Source             string
	Dest               string
	IgnoreFns          []IgnoreFn
	Flatten            bool
	RemovePrefix       string
	RemoveCommonPrefix bool
}

type ZipFileInput

type ZipFileInput struct {
	Source string
	Dest   string
}

type ZipFileListInput

type ZipFileListInput struct {
	Sources            []string
	Dest               string
	Flatten            bool
	RemovePrefix       string
	RemoveCommonPrefix bool
}

type ZipInput

type ZipInput struct {
	Files          []ZipFileInput
	Bytes          []ZipBytesInput
	Dirs           []ZipDirInput
	FileLists      []ZipFileListInput
	AddPrefix      string   // Gets added to every item
	EmptyFiles     []string // Empty files to be created
	AllowMissing   bool     // Don't error if a file/dir doesn't exist
	AllowOverwrite bool     // Don't error if a file in the zip is overwritten
}

Jump to

Keyboard shortcuts

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