Documentation ¶
Overview ¶
Package bat provides
* utility functions for builtin data structures * simple data structure implementations * common helpers
Index ¶
- func AssertIsDir(dir, key string, logger Logger)
- func AssertIsFile(filename, key string, logger Logger)
- func Atof64(s string) (float64, error)
- func Atof64Errp(s string, errp errstack.Putter) float64
- func Atoi64(s string) (int64, error)
- func Atoi64Errp(s string, errp errstack.Putter) int64
- func Atoui64(s string) (uint64, error)
- func Atoui64Errp(s string, errp errstack.Putter) uint64
- func CmpInt64Pairs(ls [][2]int64) int
- func DecodeJSON(r io.Reader, dest interface{}) errstack.E
- func DecodeJSONFile(fname string, dest interface{}, logger errstack.Logger) errstack.E
- func F64toa(x float64, precision ...int) string
- func FindRoot(callerSkipOpt ...uint) (string, errstack.E)
- func GetRawStringOfTemplate(t *template.Template, values map[string]interface{}) (string, error)
- func GzipJSON(i interface{}) ([]byte, error)
- func GzipJSONBest(i interface{}) ([]byte, error)
- func GzipJSONFast(i interface{}) ([]byte, error)
- func HashOfFile(filePath string) (string, error)
- func HumanizeInt(n uint64) string
- func I64toa(x int64) string
- func I64tox(x int64) string
- func IsDir(dir string) errstack.E
- func IsDirErrp(dir string, errp errstack.Putter)
- func IsFile(filename string) errstack.E
- func IsFileErrp(filename string, errp errstack.Putter)
- func Levenshtein(str1, str2 []rune) int
- func MapCloneStrInterface(source map[string]interface{}) map[string]interface{}
- func MapCloneStrStr(source map[string]string) map[string]string
- func MapKeysInt64Bool(m map[int64]bool) []int64
- func MapKeysStrBool(m map[string]bool) []string
- func MapKeysStrInterface(m map[string]interface{}) []string
- func MapKeysStrStr(m map[string]string) []string
- func MapKeysStrStruct(m map[string]struct{}) []string
- func MapReverseStrStr(m map[string]string) map[string]string
- func MapSortedKeysStrBool(m map[string]bool) []string
- func MapStrStrGetAnyValue(m map[string]string) string
- func MapUpdateStrInterface(source map[string]interface{}, dest *map[string]interface{})
- func MapUpdateStrStr(source map[string]string, dest *map[string]string)
- func MatchesPrefixes(s string, prefixes []string) bool
- func Min3Int(a, b, c int) int
- func MurmurHash(i interface{}) ([]byte, error)
- func MurmurHashBase64(i interface{}) (string, error)
- func MurmurHashHex(content []byte) (string, error)
- func MurmurHashSet(elems ...interface{}) ([]byte, error)
- func MurmurHashSetBase64(elems ...interface{}) (string, error)
- func RandomASCII(length int) string
- func RandomCode() string
- func RandomStrChars(length int, chars []byte) string
- func ReadFile(filename string, logger errstack.Logger) ([]byte, errstack.E)
- func RmDiacritics(s string) string
- func SliceConcat(slices ...[]interface{}) []interface{}
- func SliceIdx(slice []interface{}, x interface{}) int
- func SliceIntIdx(slice []int, x int) int
- func SliceStrAsNil(ls []string) []string
- func SliceStrConcat(slices ...[]string) []string
- func SliceStrIdx(slice []string, x string) int
- func SliceStrSliceIdx(slices [][]string, x []string) int
- func SliceStrToMap(ls []string) map[string]struct{}
- func SliceStrUniqueAppend(src []string, strs ...string) []string
- func StrIsNum(s string) bool
- func StrIsWhitespace(s string) bool
- func StrJoin(sep string, args ...string) string
- func StrTrimMultiSpace(s string) string
- func StrTruncateUpTo(s string, r rune, n int) string
- func StrsEq(a, b []string) bool
- func StrsOnlyWhitespace(ss []string) bool
- func StrsSame(a, b []string) bool
- func ToInterfaceSlice(i interface{}) ([]interface{}, error)
- func TraverseObj(v interface{}, listener func(interface{}) error, errorOnCyclic bool) error
- func TrimSuffixes(s string, suffixes ...string) string
- func UnsafeByteArrayToStr(b []byte) string
- func UnsafeStrToByteArray(s string) []byte
- func UnsafeToBytes(source interface{}) ([]byte, error)
- func UnsafeToString(source interface{}) (string, error)
- type Logger
- type Page
- type StrIterator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertIsDir ¶
AssertIsDir calls IsDir and panics if error is returned. `key` is the log argument to name the path entity.
func AssertIsFile ¶
AssertIsFile calls IsFile and panics if error is returned. `key` is the log argument to name the path entity.
func Atof64Errp ¶
Atof64Errp converts 10-based string into float64 value and sets the error in the putter.
func Atoi64Errp ¶
Atoi64Errp converts 10-based string into int64 value and sets the error in the putter.
func Atoui64Errp ¶
Atoui64Errp converts 10-based string into uint64 value and sets the error in the putter.
func CmpInt64Pairs ¶
CmpInt64Pairs compares pairs of int64 for sorting
func DecodeJSON ¶
DecodeJSON decodes JSON data from `r` into `dest`. `dest` has to be a pointer! If reader implements a Closer interface then we will call Close after decoding the input.
func DecodeJSONFile ¶
DecodeJSONFile as `DecodeJSON` but reads data from the file.
func F64toa ¶
F64toa converts float64 value to 10-based string. Function takes optional argument - precision - which is described in strconv.FormatFloat
func FindRoot ¶
FindRoot returns an absolute path to the project root, defined by the existance of .git directory or .hg directory based on the caller stack trace or path to the executable file. It takes one optional argument: `callerSkip` -- the number of additional stack frames to skip above *this* function call to use in by te stack trace strategy.
func GetRawStringOfTemplate ¶
GetRawStringOfTemplate executes a template with given values and returns resulting string
func GzipJSONBest ¶
GzipJSONBest encodes as JSON and compress with Gzip in best compression level
func GzipJSONFast ¶
GzipJSONFast encodes as JSON and compress with Gzip in fastest compression level
func HashOfFile ¶
HashOfFile computes murmur3 hash of the given file via its path
func HumanizeInt ¶
HumanizeInt produces a human readable representation of an SI size.
func IsDirErrp ¶
IsDirErrp check if `dir` is a valid path to a directory and sets the error in the putter.
func IsFileErrp ¶
IsFileErrp check if `filename` is a valid path to a file and sets the error in the putter.
func Levenshtein ¶
Levenshtein computes the Levenshtein distance. It's a measure of the similarity between two strings, which we will refer to as the source string (s) and the target string (t). The distance is the number of deletions, insertions, or substitutions required to transform s into t. For example, the Levenshtein distance between "Asheville" and "Arizona" is 8.
func MapCloneStrInterface ¶
MapCloneStrInterface will clone a given map[str]interface{} to a new one
func MapCloneStrStr ¶
MapCloneStrStr will clone a given map[string]string{} to a new one
func MapKeysInt64Bool ¶
MapKeysInt64Bool returns a sorted list of keys from a map[int64]bool
func MapKeysStrBool ¶
MapKeysStrBool returns a list of keys from a map[string]bool
func MapKeysStrInterface ¶
MapKeysStrInterface returns a sorted list of keys from a map[string]nterface{}
func MapKeysStrStr ¶
MapKeysStrStr returns a sorted list of keys from map[string]string
func MapKeysStrStruct ¶
MapKeysStrStruct returns a sorted list of keys from a map[string]struct{}
func MapReverseStrStr ¶
MapReverseStrStr reverses keys and values of given map If same value exists multiple times, the one with bigger key wins to give deterministic ordering and to make it testable. {"a": "1", "b": 1} -> {"1": "b"}
func MapSortedKeysStrBool ¶
MapSortedKeysStrBool returns a list of sorted keys from a map[string]bool
func MapStrStrGetAnyValue ¶
MapStrStrGetAnyValue returns any values from the map or empty string if map is empty
func MapUpdateStrInterface ¶
MapUpdateStrInterface loads destination map into source map.
func MapUpdateStrStr ¶
MapUpdateStrStr loads destination map into source map. If dest is empty it will create a new map.
func MatchesPrefixes ¶
MatchesPrefixes checks if given string has a prefix from given prefix list
func MurmurHash ¶ added in v1.0.1
MurmurHash computes murmur hash of the provided object
func MurmurHashBase64 ¶ added in v1.0.1
MurmurHashBase64 computes murmur string hash of the provided object
func MurmurHashHex ¶ added in v1.0.1
MurmurHashHex takes murmur hash and encodes hash into hex
func MurmurHashSet ¶ added in v1.0.1
MurmurHashSet computes murmur hash of the provided set of objects. Hash will have the save value regardless of objects order.
func MurmurHashSetBase64 ¶ added in v1.0.1
MurmurHashSetBase64 computes murmur string hash of the provided set of objects
func RandomASCII ¶
RandomASCII uses RandomStrChars to returns a new random string consisting of ASCII alphabet.
func RandomCode ¶
func RandomCode() string
RandomCode generates a random code where random long integer is serialized into hex string
func RandomStrChars ¶
RandomStrChars returns a new random string of the provided length, consisting of the provided byte slice of allowed characters (maximum 256). The generated result is a cryptographically secure uniform (unbiased) strings. This code is based on the Go unri package and is a subject of public domain:
http://creativecommons.org/publicdomain/zero/1.0/
func RmDiacritics ¶
RmDiacritics removes diacritics from a string. If non-alphanumeric character is encountered diacritics are removed from it. If removing diacritics is not possible, character is removed.
func SliceConcat ¶
func SliceConcat(slices ...[]interface{}) []interface{}
SliceConcat concats all given slices into a new slice
func SliceIdx ¶
func SliceIdx(slice []interface{}, x interface{}) int
SliceIdx returns first index of `x` in `slice` and -1 if `x` is not present.
func SliceIntIdx ¶
SliceIntIdx returns first index of `x` in `slice` and -1 if `x` is not present.
func SliceStrAsNil ¶
SliceStrAsNil returns initialized empty slice as nil
func SliceStrConcat ¶
SliceStrConcat concats all given string slices into a new slice
func SliceStrIdx ¶
SliceStrIdx returns first index of `x` in `slice` and -1 if `x` is not present.
func SliceStrSliceIdx ¶
SliceStrSliceIdx returns first index of `x` in `slices` and -1 if `x` is not present.
func SliceStrToMap ¶
SliceStrToMap creates a map from string slice for frequent search in slice
func SliceStrUniqueAppend ¶
SliceStrUniqueAppend appends `strs` strings into source without excluding elements which alread exist in `src`.
func StrIsWhitespace ¶
StrIsWhitespace check if string contains only whitespace characters
func StrTrimMultiSpace ¶
StrTrimMultiSpace replaces multiple spaces with one space and also trims space from both ends
func StrTruncateUpTo ¶
StrTruncateUpTo cut a part of a string `s` after n occurrence of `r`
func StrsOnlyWhitespace ¶
StrsOnlyWhitespace checks if input consists of only whitespace
func ToInterfaceSlice ¶
func ToInterfaceSlice(i interface{}) ([]interface{}, error)
ToInterfaceSlice converts given slice into empty interface slice. Mostly for batch DB operations
func TraverseObj ¶
TraverseObj traverses `v` and sends all encountered values to the listener. Traversal is stable, so values will always come in the same order. Only simple values (like `int` or `string`) will be send to listener. Error is returned only if cycle is detected in the traversed object and `errorOnCyclic` is true. Otherwise cyclic references are ignored.
func TrimSuffixes ¶
TrimSuffixes returns s without any of the provided trailing suffixes strings.
func UnsafeByteArrayToStr ¶
UnsafeByteArrayToStr uses unsafe to convert byte array into string. Supplied array cannot be altered after this functions is called
func UnsafeStrToByteArray ¶
UnsafeStrToByteArray uses unsafe to convert string into byte array. Returned array cannot be altered after this functions is called
func UnsafeToBytes ¶
UnsafeToBytes converts string or []byte to []byte
func UnsafeToString ¶
UnsafeToString converts string or []byte to string
Types ¶
type Logger ¶
type Logger interface { Error(msg string, ctx ...interface{}) // Fatal is a Crit log followed by panic Fatal(msg string, ctx ...interface{}) }
Logger interface
type StrIterator ¶
StrIterator provides a generator of names / strings