genutil

package module
v0.0.0-...-bdd0758 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2016 License: GPL-3.0 Imports: 21 Imported by: 0

README

genutil

genutil collects in place the utility functions used in various LDCS golang scripts

GoDoc

Documentation

Overview

Package genutil collects in place the utility functions used in various golang scripts

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbsInt

func AbsInt(_ival int) int

AbsInt is shorthand

func AbsInt64

func AbsInt64(_ival int64) int64

AbsInt64 is shorthand

func AddCalDate

func AddCalDate(_date string, _offset int) string

AddCalDate adds number of dates to specified date

func AllDirs

func AllDirs(_dir string) (paths, dirs []string)

AllDirs returns array of all parental dirs. You should provide it a good dir

func AnyPathOK

func AnyPathOK(_path string) bool

AnyPathOK checks for a readable file in one of the supported compression formats

func AnySplit

func AnySplit(str, splitstr string) []string

AnySplit splits input string into parts, using any char in splitstr

func AnySplit2

func AnySplit2(str, splitstr string) (splitter, part0, part1 string)

AnySplit2 splits input string in upto 2 parts, using any char in splitstr

func AnySplit3

func AnySplit3(str, splitstr string) (splitter0, splitter2, part0, part1, part2 string)

AnySplit3 splits input string in upto 3 parts, using any char in splitstr

func BashExecOrDie

func BashExecOrDie(_verbose bool, _cmd, _dir string) string

BashExecOrDie executes the string cmd with /bin/bash and panics on any kind of failure

func ByteToint0

func ByteToint0(_str []byte) int

ByteToint0 converts bytestring to int, with default 0

func CalDatelist

func CalDatelist(_begdate, _enddate string, _includeBeg, _includeEnd bool) []string

CalDatelist creates list of dates from the range, possibly including/excluding the begin/end dates

func CalcPriceIfZero

func CalcPriceIfZero(_px, _badpx string, _val, _qty float64) string

CalcPriceIfZero returns price calculation if the input price was bad

func CallerInfo2

func CallerInfo2() string

CallerInfo2 is used to embellish error messages with the caller name

func CheckFileIsReadableAndNonzeroOrDie

func CheckFileIsReadableAndNonzeroOrDie(_fname string)

CheckFileIsReadableAndNonzeroOrDie is shorthand

func ChompChar

func ChompChar(_str string, _chompchar uint8) string

ChompChar eliminates suffix char if present

func ChompParens

func ChompParens(_str string, _trimSpace bool) string

ChompParens eliminates dual delimiting strings if present

func ChompQuotes

func ChompQuotes(_str string, _trimSpace bool) string

ChompQuotes eliminates dual delimiting quotes if present

func ChompStr

func ChompStr(_str, _chompstr string) string

ChompStr eliminates suffix string if present

func CleanAndSplitOnSeparator

func CleanAndSplitOnSeparator(_str, _insep, _sep string) []string

CleanAndSplitOnSeparator trims each line obtained by splitting input paragraph at newline. Each line is split on separator insep, and joined back by specified separator

func CleanAndSplitOnSpaces

func CleanAndSplitOnSpaces(_str, _sep string) []string

CleanAndSplitOnSpaces trims each line obtained by splitting input paragraph at newline. Each line is split on space, and joined back by specified separator

func CleanString

func CleanString(_str string) string

CleanString replaces comma with semi

func CleanStringMaximally

func CleanStringMaximally(_str string) string

CleanStringMaximally removes various chars from name

func ColonSplit2

func ColonSplit2(str string) (part1, part2 string)

ColonSplit2 is shorthand splitter

func ColonSplit3

func ColonSplit3(str string) (part1, part2, part3 string)

ColonSplit3 is shorthand splitter

func ColonSplit4

func ColonSplit4(str string) (part0, part1, part2, part3 string)

ColonSplit4 is shorthand splitter

func ColonSplit5

func ColonSplit5(str string) (part0, part1, part2, part3, part4 string)

ColonSplit5 is shorthand splitter

func ColonSplit5Len

func ColonSplit5Len(str string) (nn int, part0, part1, part2, part3, part4 string)

ColonSplit5Len is shorthand splitter, which also returns the number of parts found

func CommaSplit2

func CommaSplit2(str string) (part0, part1 string)

CommaSplit2 is shorthand splitter

func CommaSplit7

func CommaSplit7(str string) (part0, part1, part2, part3, part4, part5, part6 string)

CommaSplit7 is shorthand splitter

func CompressType

func CompressType(_fname string) int

CompressType returns a numeric code based on the compression type indicated in the filename

func CompressionBasename

func CompressionBasename(_fname string) string

CompressionBasename returns uncompressed filename of the input filename

func CopyStrSlice

func CopyStrSlice(_strarr []string, _prefix, _suffix string) []string

CopyStrSlice copies a string slice, optionally with prefix and suffix

func CsvCountTuple

func CsvCountTuple(_csvlist, _sep string) int

CsvCountTuple counts the number of parts under specified separator

func CsvLastTuple

func CsvLastTuple(_csvlist, _sep string) string

CsvLastTuple returns the last item in the tuple, or blank

func CsvLastTupleElem

func CsvLastTupleElem(_csvlist, _sep, _elemsep, _badval string, _partno int) string

CsvLastTupleElem returns the numbered sub-element of the csv's last element (itself viewed as an elemlist)

func DDDashMMDashYY2YYYYMMDD

func DDDashMMDashYY2YYYYMMDD(_dt string) string

DDDashMMDashYY2YYYYMMDD is shorthand convert 9-FEB-13 (DD-MMM-YY) --> 20130209 (YYYYMMDD)

func DDSlashMMSlashYYYY2YYYYMMDD

func DDSlashMMSlashYYYY2YYYYMMDD(_dt string) string

DDSlashMMSlashYYYY2YYYYMMDD is shorthand convert 27/11/2013 (DD/MM/YYYY) --> 20131127 (YYYYMMDD) convert 9/2/2013 (D/M/YYYY) --> 20130209 (YYYYMMDD)

func DD_MMM_YY2yyyymmdd

func DD_MMM_YY2yyyymmdd(_bsl []byte) int64

DD_MMM_YY2yyyymmdd converts date format

func DashSplit2

func DashSplit2(str string) (part0, part1 string)

DashSplit2 is shorthand splitter

func Date2YYYYMMDD

func Date2YYYYMMDD(_today, _dt string) string

Date2YYYYMMDD converts a date (by guessing) from one of several formats to YYYYMMDD

func DateParts

func DateParts(_date string) (int, int)

DateParts is a utility to convert some date mnemonics Do not call this directly for NBD/PBD etc, although today might be sort of safe

func EmptyIfZero

func EmptyIfZero(_num, _ccy string) string

EmptyIfZero returns empty string or the currency amount if nonzero

func EnsureDirOrDie

func EnsureDirOrDie(_dirBase, _dirName string) string

EnsureDirOrDie dies if the dir did not exist and could not be created

func EqualAndZeroStrings

func EqualAndZeroStrings(_lstr, _rstr string) bool

EqualAndZeroStrings tells if strings are equal, and both zero

func EqualFloats

func EqualFloats(_f1, _f2 float64) bool

EqualFloats tells if floats are equal

func EqualsSplit2

func EqualsSplit2(str string) (part0, part1 string)

EqualsSplit2 is shorthand splitter

func EqualsSplit2Trimmed

func EqualsSplit2Trimmed(str string) (part0, part1 string)

EqualsSplit2Trimmed is shorthand splitter

func EqualsSplit6

func EqualsSplit6(str string) (part0, part1, part2, part3, part4, part5 string)

EqualsSplit6 is shorthand splitter

func ExecCommandOrDie

func ExecCommandOrDie(_verbose bool, _cmd string)

ExecCommandOrDie executes the given command and panics on any kind of failure

func FileAsofCurrent

func FileAsofCurrent(_path, _dt string, _num int) string

FileAsofCurrent replaces YYYYMMDD with older dates until it finds a readable file (any compression variant) Today is considered

func FileAsofPrevious

func FileAsofPrevious(_path, _dt string, _num int) string

FileAsofPrevious replaces YYYYMMDD with older dates until it finds a readable file (any compression variant) Today is not considered

func FileExecutable

func FileExecutable(_path string) bool

FileExecutable returns whether the given file or directory exists or not, and is executable

func FileInfo

func FileInfo(_fname, _sep string, _fullinfo bool) string

FileInfo formats file info into readable form

func FileInfoSysStr

func FileInfoSysStr(_sys interface{}, _sep string) string

FileInfoSysStr formats file info into readable form call it with stat.Sys()

func FileList

func FileList(_dname string) []string

FileList returns files in dir

func FileSize

func FileSize(_fname string) int

FileSize returns -1 if file not found

func FilenameExpandUser

func FilenameExpandUser(_fname string) string

func FillDate

func FillDate(pat string, ctime time.Time) string

FillDate instantiates the date pattern from specified date

func Flatline2

func Flatline2(_str0, _str1 string) string

Flatline2 combines 2 strings, potentially eliminating newline on the first

func FlipIfFalseFloat

func FlipIfFalseFloat(_flipIfFalse bool, _val1, _val2 float64) (float64, float64)

FlipIfFalseFloat helps compensate for golang not having ternary op a

func FlipIfFalseInt

func FlipIfFalseInt(_flipIfFalse bool, _val1, _val2 int) (int, int)

FlipIfFalseInt helps compensate for golang not having ternary op a

func FlipIfFalseInt64

func FlipIfFalseInt64(_flipIfFalse bool, _val1, _val2 int64) (int64, int64)

FlipIfFalseInt64 helps compensate for golang not having ternary op a

func FlipIfFalseStr

func FlipIfFalseStr(_flipIfFalse bool, _val1, _val2 string) (string, string)

FlipIfFalseStr helps compensate for golang not having ternary op a

func Float64ToHuman

func Float64ToHuman(num float64) string

Float64ToHuman is shorthand

func FloatTernary

func FloatTernary(_aIfTrue bool, _a, _b float64) float64

FloatTernary is shorthand

func GenKVFromMap

func GenKVFromMap(_kvmap map[string]string) string

GenKVFromMap returns the map as a csvlist of kvps

func GetFileLineCount

func GetFileLineCount(_fname, _comments string) (int64, error)

GetFileLineCount counts non-comment lines of a file

func GetKV

func GetKV(_list, _kk, _def string) string

GetKV obtains the value from csvlist of kvps or the default

func GetKVFloat

func GetKVFloat(_list, _kk string, _def float64) float64

GetKVFloat obtains the value from csvlist of kvps or the default

func GetLastSunday

func GetLastSunday(_timezone string) string

GetLastSunday returns the most recent sunday

func GetLatestDatedDir

func GetLatestDatedDir(parentdir string) string

GetLatestDatedDir is shorthand

func GetLatestFileWithPattern

func GetLatestFileWithPattern(pattern string) string

GetLatestFileWithPattern is shorthand

func GetLogicalDate

func GetLogicalDate(_timezone string, _time string) string

GetLogicalDate returns today. Or tomorrow if it is now past the specified time.

func GetMapFromKV

func GetMapFromKV(_list string) map[string]string

GetMapFromKV returns the csvlist of kvps as a map

func GetNocasekeyKV

func GetNocasekeyKV(_list, _kk, _def string) string

GetNocasekeyKV (case-insensitively) obtains the value from csvlist of kvps or the default.

func GetNumLines

func GetNumLines(_fname string) int64

GetNumLines counts number of lines in any compression variant of file

func GetParentDir

func GetParentDir(_dir string) (parent string, ok bool)

GetParentDir returns parent dir of supplied dir, setting bool to false if no parent

func GetSecondLatestFileWithPattern

func GetSecondLatestFileWithPattern(pattern string) string

GetSecondLatestFileWithPattern is shorthand

func GetSplitTrimmedPart

func GetSplitTrimmedPart(_str, _sep, _badstr string, _partno int) string

GetSplitTrimmedPart returns the numbered part (or _badstr if there was an error)

func GetSplitTrimmedPartFloat64

func GetSplitTrimmedPartFloat64(_str, _sep string, _bad float64, _partno int) float64

GetSplitTrimmedPartFloat64 returns the numbered part (or _bad if there was an error)

func GetSplitTrimmedPartInt64

func GetSplitTrimmedPartInt64(_str, _sep string, _bad int64, _partno int) int64

GetSplitTrimmedPartInt64 returns the numbered part (or _bad if there was an error)

func GetYyyymmddFromFilenameYymmddFromEndWithSuffixLen

func GetYyyymmddFromFilenameYymmddFromEndWithSuffixLen(_fname string, _suffLen int, _def string) string

GetYyyymmddFromFilenameYymmddFromEndWithSuffixLen grabs the YYMMDD from filenames of form foo_YYMMDD.zip, but extend with the decade

func GetYyyymmddFromFilenameYyyymmFromEndWithSuffixLen

func GetYyyymmddFromFilenameYyyymmFromEndWithSuffixLen(_fname string, _suffLen int, _def string) string

GetYyyymmddFromFilenameYyyymmFromEndWithSuffixLen grab the YYMMDD from filenames of form foo_YYYYMM.zip, but extend with 1st day of month

func Green

func Green(in string) (out string)

Green sets a color

func GreenBold

func GreenBold(in string) (out string)

GreenBold sets a color

func HatSplit2

func HatSplit2(str string) (part0, part1 string)

HatSplit2 is shorthand splitter

func Hhmmss2Seconds

func Hhmmss2Seconds(_hhmmss string) float64

Hhmmss2Seconds converts to (possibly fractional) seconds

func Hhmmss2Timetz

func Hhmmss2Timetz(_localTime, _timezone string) (time.Time, bool)

Hhmmss2Timetz converts specified HHMMSS time to today in the specified timezone, return in time.Time It returns false if tz is invalid

func Hhmmsstz2Timetz

func Hhmmsstz2Timetz(_time, _fromTZ, _toTZ string) (string, bool)

Hhmmsstz2Timetz converts HHMMSS time in one timezone (fromTZ) to another (toTZ)

func Hostname

func Hostname() string

Hostname retrieves hostname

func IncrementMaxId

func IncrementMaxId(_idmap *map[string]int64, _kk string) int64

IncrementMaxId increments the max id

func IndexNl

func IndexNl(_buffer []byte, _buflen, _rowBegin int) int

IndexNl finds newline in byte buffer of len _buflen starting at _rowBegin

func Int64Ternary

func Int64Ternary(_aIfTrue bool, _a, _b int64) int64

Int64Ternary is shorthand

func IntSliceContains

func IntSliceContains(_sl []int, _num int) bool

IntSliceContains is shorthand

func IntTernary

func IntTernary(_aIfTrue bool, _a, _b int) int

IntTernary is shorthand

func IsCancellingStrings

func IsCancellingStrings(_lstr, _rstr string, _leftneg *bool) bool

IsCancellingStrings checks if strings are offsetting numbers, and informs which is the negative one

func IsCommentLine

func IsCommentLine(_line []byte, _commenttags []string) bool

IsCommentLine checks if a line is one of the list of comment types

func IsDigit

func IsDigit(_bb byte) bool

IsDigit is shorthand

func IsPositiveInteger

func IsPositiveInteger(_str string) bool

IsPositiveInteger returns true if the string is int > 0

func IsYYYYMMDD

func IsYYYYMMDD(_str string) bool

IsYYYYMMDD is shorthand

func IsZipFilename

func IsZipFilename(_fname string) bool

IsZipFilename checks for any kind of .zip or .ZIP or .ZiP file

func JoinSlice

func JoinSlice(_strarr []string, _sep string) string

JoinSlice joins slice elements using named separator

func JoinSliceLimitingColumns

func JoinSliceLimitingColumns(_strarr []string, _sep, _rowsep string, _maxcol int) string

JoinSliceLimitingColumns joins slice elements using named separator, and breaking into new "rows" when max cols is reached

func JoinSliceWithReverse

func JoinSliceWithReverse(_strarr []string, _sep string, _reverse bool) string

JoinSliceWithReverse joins slice elements using named separator, and optionally in reverse

func KB2GB

func KB2GB(_kb string) string

KB2GB is shorthand

func KeysBoolMap

func KeysBoolMap(_aset *map[string]bool) []string

KeysBoolMap is shorthand

func Kilos

func Kilos(num float64) string

Kilos is shorthand

func ListContainsByte

func ListContainsByte(_bb byte, _list ...byte) bool

ListContainsByte checks if given byte is in list

func ListContainsStr

func ListContainsStr(_str string, _list ...string) bool

ListContainsStr checks if given string is in list

func MMDDYYYY2yyyymmdd

func MMDDYYYY2yyyymmdd(_bsl []byte) int64

MMDDYYYY2yyyymmdd converts bytestring date of 02/03/2014 format to int64

func MMM2MM

func MMM2MM(_MMM string) string

MMM2MM is shorthand

func MMSlashDDSlashYYYY2YYYYMMDD

func MMSlashDDSlashYYYY2YYYYMMDD(_dt string) string

MMSlashDDSlashYYYY2YYYYMMDD is shorthand convert 11/27/2013 (MM/DD/YYYY) --> 20131127 (YYYYMMDD) convert 2/9/2013 (M/D/YYYY) --> 20130209 (YYYYMMDD)

func MakeDirOrDie

func MakeDirOrDie(_dirBase, _dirName string) string

MakeDirOrDie panics if unable to create the dir (or if it exists)

func MaxFloat

func MaxFloat(_ival1, _ival2 float64) float64

MaxFloat is shorthand

func MaxInt

func MaxInt(_ival1, _ival2 int) int

MaxInt is shorthand

func MaxInt64

func MaxInt64(_ival1, _ival2 int64) int64

MaxInt64 is shorthand

func Millions

func Millions(num float64) string

Millions is shorthand

func MinFloat

func MinFloat(_ival1, _ival2 float64) float64

MinFloat is shorthand

func MinInt

func MinInt(_ival1, _ival2 int) int

MinInt is shorthand

func MinInt64

func MinInt64(_ival1, _ival2 int64) int64

MinInt64 is shorthand

func ModifyKV

func ModifyKV(_list, _kk, _val string) string

ModifyKV updates the value in a csvlist of kvps

func NewBoolMap

func NewBoolMap() map[string]bool

NewBoolMap returns a map of string to true

func NewBoolMapFromCsv

func NewBoolMapFromCsv(_csv, _sep string) map[string]bool

NewBoolMapFromCsv returns a map where each element of the supplied string is set true

func NewInt64BoolMap

func NewInt64BoolMap() map[int64]bool

NewInt64BoolMap is shorthand

func Now

func Now() string

Now is shorthand

func NowTZ

func NowTZ(_timezone string) string

NowTZ returns today in specified timezone

func OpenAny

func OpenAny(_fname string) *bufio.Reader

OpenAny returns buffered reader for the content of the specified file, or available compression variant

func OpenAnyErr

func OpenAnyErr(_fname string) (*bufio.Reader, error)

OpenAnyErr returns buffered reader for the content of the specified file, or available compression variant It is more error conscious than OpenAny()

func OpenAnyIO

func OpenAnyIO(_fname string) *io.Reader

OpenAnyIO returns unbuffered reader for the content of the specified file, or available compression variant

func OverrideWithKVMap

func OverrideWithKVMap(_mp map[string]string, _key, _alt string) string

OverrideWithKVMap does map lookup with a default

func PathExists

func PathExists(_path string) (bool, error)

PathExists returns whether the given file or directory exists or not

func PathIsDir

func PathIsDir(_path string) bool

PathIsDir checks if path is dir

func PathOK

func PathOK(_path string) bool

PathOK is shorthand

func PathRemoveOrPanic

func PathRemoveOrPanic(_fname string) bool

PathRemoveOrPanic panics if it fails to remove a directory

func PreviousYYYYMM

func PreviousYYYYMM(_dt string) string

PreviousYYYYMM is shorthand

func PreviousYYYYMMDD

func PreviousYYYYMMDD(_dt string, _num int) string

PreviousYYYYMMDD is shorthand

func ReadableFilename

func ReadableFilename(_fname string) (ofname string, ofcmd *exec.Cmd, ofcode int)

ReadableFilename returns information for subsequent reading of the specified file If not found, it looks for compression variants of the file

func ReadableFilenameCommand

func ReadableFilenameCommand(_fname string) string

ReadableFilenameCommand returns the command portion of the output of ReadableFilename()

func ReadableFilenameTimestamp

func ReadableFilenameTimestamp(_fname string) string

ReadableFilenameTimestamp returns the timestamp of the output of ReadableFilename()

func Red

func Red(in string) (out string)

Red sets a color

func RedBold

func RedBold(in string) (out string)

RedBold sets a color

func RemoveCompressionVariants

func RemoveCompressionVariants(_fname string, _keepbase bool)

RemoveCompressionVariants removes all compression variants of the specified filename, optionally preserving the base filename

func ResolveDir

func ResolveDir(_dir string, doCheck bool) string

ResolveDir returns Directory after resolving multiple dots, for example ..../foo will return absolute path in great-grand-parent dir Optionally it will check if the directory exists Return empty string on any error

func Resplit

func Resplit(_str, _osep, _njoin, _nsep string) []string

Resplit replaces separator with another, then splits it on yet another separator

func SearchForFileWithPattern

func SearchForFileWithPattern(pat string) (bool, string)

SearchForFileWithPattern is shorthand

func SepMap

func SepMap(_sep string, _anycase bool) string

SepMap obtains the separator

func SepReplace

func SepReplace(_str, _insep, _outsep string) string

SepReplace replaces one named separator with another

func SepSplit2

func SepSplit2(str, _sep string) (part0, part1 string)

SepSplit2 is shorthand splitter

func SepSplit4

func SepSplit4(str, _sep string) (part0, part1, part2, part3 string)

SepSplit4 is shorthand splitter

func SetupLogger

func SetupLogger(_logfilepath, _logcontentprefix string) (lglocal *log.Logger, err error)

SetupLogger returns a logger

func ShrinkSep

func ShrinkSep(_str string, _ch byte) string

ShrinkSep removes Semi at EOL and shrinks multiple Semi to single Semi prior to EOL

func SlashSplit2

func SlashSplit2(str string) (part0, part1 string)

SlashSplit2 is shorthand splitter

func SlashSplit3

func SlashSplit3(str string) (part0, part1, part2 string)

SlashSplit3 is shorthand splitter

func SlashSplit5

func SlashSplit5(str string) (part0, part1, part2, part3, part4 string)

SlashSplit5 is shorthand splitter

func SliceContainsStr

func SliceContainsStr(s []string, e string) bool

SliceContainsStr checks if given string is in the slice

func SliceFloatsAdd

func SliceFloatsAdd(_arr []float64) float64

SliceFloatsAdd adds slice elements of the slice

func SliceIndexStr

func SliceIndexStr(s []string, e string) int

SliceIndexStr calculates index of string in slice

func SmartFlatline2

func SmartFlatline2(_str0, _str1 string) string

SmartFlatline2 combines 2 strings, potentially eliminating newline on the first. In addition, it guesses whether to insert line-ending period.

func SortedKeysByVal_String2Float64_AbsAscending

func SortedKeysByVal_String2Float64_AbsAscending(_mp *map[string]float64) []string

SortedKeysByVal_String2Float64_AbsAscending sorts by value for that maptype

func SortedKeysByVal_String2Float64_AbsDescending

func SortedKeysByVal_String2Float64_AbsDescending(_mp *map[string]float64) []string

SortedKeysByVal_String2Float64_AbsDescending sorts by value for that maptype

func SortedKeysByVal_String2Float64_Ascending

func SortedKeysByVal_String2Float64_Ascending(_mp *map[string]float64) []string

SortedKeysByVal_String2Float64_Ascending sorts by value for that maptype

func SortedKeysByVal_String2Float64_Descending

func SortedKeysByVal_String2Float64_Descending(_mp *map[string]float64) []string

SortedKeysByVal_String2Float64_Descending sorts by value for that maptype

func SortedKeys_Int2Int

func SortedKeys_Int2Int(_mp *map[int]int) []int

SortedKeys_Int2Int returns sorted keys of that type

func SortedKeys_String2Bool

func SortedKeys_String2Bool(_mp *map[string]bool) []string

SortedKeys_String2Bool returns sorted keys of that type

func SortedKeys_String2Float64

func SortedKeys_String2Float64(_mp *map[string]float64) []string

SortedKeys_String2Float64 returns sorted keys of that type

func SortedKeys_String2Int

func SortedKeys_String2Int(_mp *map[string]int) []string

SortedKeys_String2Int returns sorted keys of that type

func SortedKeys_String2Int64

func SortedKeys_String2Int64(_mp *map[string]int64) []string

SortedKeys_String2Int64 returns sorted keys of that type

func SortedKeys_String2String

func SortedKeys_String2String(_mp *map[string]string) []string

SortedKeys_String2String returns sorted keys of that type

func SortedUniqueKeys

func SortedUniqueKeys(_strs ...[]string) (strs []string)

SortedUniqueKeys returns sorted array of unique strings within the input string array

func SpaceSplit2

func SpaceSplit2(str string) (part0, part1 string)

SpaceSplit2 is shorthand splitter

func SpaceSplitter

func SpaceSplitter(inp rune) bool

SpaceSplitter informs if the input char is a split char

func SplitFilename

func SplitFilename(_fname string, _extlist []string) (string, string, bool)

SplitFilename returns (filename, extension, ok) from the input filename, for an allowed list of extensions, e.g. ["txt", "DAT", ...]

func SplitFilename2

func SplitFilename2(_str string, _ii interface{}) (string, string)

SplitFilename2 splits based on (consumed) string or position (negative counts from right)

func SplitFilename3

func SplitFilename3(_str string, _ii0, _ii1 interface{}) (string, string, string)

SplitFilename3 splits into 3 parts, using delim which is either string or positional index (which may be negative for counting from end)

func SplitFilename4

func SplitFilename4(_str string, _ii0, _ii1, _ii2 interface{}) (string, string, string, string)

SplitFilename4 splits into 4 parts, using delim which is either string or positional index (which may be negative for counting from end)

func SplitOrNull

func SplitOrNull(_str, _sep string) []string

SplitOrNull on empty input returns null slice, unlike plain strings.Split which will return 1 element slice

func SplitToIntSlice

func SplitToIntSlice(_str, _sep string) []int

SplitToIntSlice convert "1,2,3" to slice of ints

func SplitToStrSlice

func SplitToStrSlice(_str, _sep string) []string

SplitToStrSlice converts "1,2,3" to slice of strings, ignoring blanks

func SplitYYYYMMDD

func SplitYYYYMMDD(_yyyymmdd int64) (yyyy, mm, dd int64)

SplitYYYYMMDD splits date into parts

func Str2Bool

func Str2Bool(_str string) bool

Str2Bool is shorthand

func StrAbs

func StrAbs(_num string) string

StrAbs returns the abs value of a string, as string

func StrAbsDivFloat

func StrAbsDivFloat(_bsl1 string, _num float64) string

StrAbsDivFloat is shorthand

func StrAddFloat

func StrAddFloat(_bsl1 string, _num float64) string

StrAddFloat is shorthand

func StrAddInt

func StrAddInt(_bsl1 string, _num int64) string

StrAddInt is shorthand

func StrAddint

func StrAddint(_bsl1 string, _num int) string

StrAddint is shorthand

func StrAorB

func StrAorB(_a, _b string) string

StrAorB is shorthand

func StrCapped

func StrCapped(_str string, _cap int) string

StrCapped returns truncated string if exceeds cap

func StrDivFloat

func StrDivFloat(_bsl1 string, _num float64) string

StrDivFloat is shorthand

func StrDropComponent

func StrDropComponent(_str, _sep string, _drop int, _doPanic bool) (string, string)

StrDropComponent drops the indicated component

func StrFloatsAbsDiff

func StrFloatsAbsDiff(_bsl1, _bsl2 string) string

StrFloatsAbsDiff is shorthand

func StrFloatsAdd

func StrFloatsAdd(_bsl1, _bsl2 string) string

StrFloatsAdd is shorthand

func StrFloatsAplusBminusC

func StrFloatsAplusBminusC(_bsl1, _bsl2, _bsl3 string) string

StrFloatsAplusBminusC is shorthand

func StrFloatsAplusminusBminusC

func StrFloatsAplusminusBminusC(_bsl1 string, _plusminus int64, _bsl2, _bsl3 string) string

StrFloatsAplusminusBminusC is shorthand

func StrFloatsDiff

func StrFloatsDiff(_bsl1, _bsl2 string) string

StrFloatsDiff is shorthand

func StrFloatsDiv

func StrFloatsDiv(_bsl1, _bsl2, _def string) string

StrFloatsDiv is shorthand

func StrFloatsMult

func StrFloatsMult(_bsl1, _bsl2 string) string

StrFloatsMult is shorthand

func StrFloatsMult3Zero

func StrFloatsMult3Zero(_bsl1, _bsl2, _bsl3 string) string

StrFloatsMult3Zero returns 0 if any items are missing

func StrIntsAdd

func StrIntsAdd(_bsl1, _bsl2 string) string

StrIntsAdd is shorthand

func StrInvert

func StrInvert(_bsl1 string) string

StrInvert is shorthand

func StrIsInt

func StrIsInt(_str string) bool

StrIsInt checks whether the string is an int

func StrMultFloat

func StrMultFloat(_bsl1 string, _num float64) string

StrMultFloat returns the result as a float, of multiplying a string and a float

func StrNegate

func StrNegate(_bsl1 string) string

StrNegate is shorthand

func StrNonzeroAorB

func StrNonzeroAorB(_a, _accy, _b, _bccy string) string

StrNonzeroAorB returns empty string or one of the currency amounts if nonzero

func StrReplaceComponent

func StrReplaceComponent(_str, _sep string, _reploc int, _rep string, _doPanic bool) (string, string)

StrReplaceComponent replaces the indicated component

func StrReplaceWithMap

func StrReplaceWithMap(_instr string, _mp map[string]string) string

StrReplaceWithMap replaces substrings in the input string based on the map passed

func StrSignAsFloat

func StrSignAsFloat(_bsl1 string, _snum float64) string

StrSignAsFloat is shorthand

func StrSin

func StrSin(_str, _sin string) bool

StrSin checks if _str is in one of the items in list specified as "(foo|bar|baz|...)"

func StrSliceContains

func StrSliceContains(_sl []string, _num string) bool

StrSliceContains is shorthand

func StrTernary

func StrTernary(_aIfTrue bool, _a, _b string) string

StrTernary is shorthand for the missing golang string ternary operatory

func StrToFloat

func StrToFloat(_bsl string) float64

StrToFloat converts string to float

func StrToFloatAbs

func StrToFloatAbs(_bsl string) float64

StrToFloatAbs converts string to absolute float

func StrYYYY_MM_DD2yyyymmdd

func StrYYYY_MM_DD2yyyymmdd(_dt string) string

StrYYYY_MM_DD2yyyymmdd removes underscores or spaces from date

func StryyyymmddInRange

func StryyyymmddInRange(_yyyymmdd, _startdate, _enddate string) bool

StryyyymmddInRange checks if STARTDATE <= yyyymmdd <= ENDDATE

func StryyyymmddInRangeClosedOpen

func StryyyymmddInRangeClosedOpen(_yyyymmdd, _startdate, _enddate string) bool

StryyyymmddInRangeClosedOpen checks if STARTDATE <= yyyymmdd < ENDDATE

func StryyyymmddInRangeOpenClosed

func StryyyymmddInRangeOpenClosed(_yyyymmdd, _startdate, _enddate string) bool

StryyyymmddInRangeOpenClosed checks if STARTDATE < yyyymmdd <= ENDDATE

func StryyyymmddInRangeOpenOpen

func StryyyymmddInRangeOpenOpen(_yyyymmdd, _startdate, _enddate string) bool

StryyyymmddInRangeOpenOpen checks if STARTDATE < yyyymmdd < ENDDATE

func StryyyymmddLT

func StryyyymmddLT(_dt1, _dt2 string) bool

StryyyymmddLT returns true if firstdate < seconddate use AddCalDate if you want to compare offsetted dates

func StryyyymmddLTEQ

func StryyyymmddLTEQ(_dt1, _dt2 string) bool

StryyyymmddLTEQ returns true if firstdate <= seconddate use AddCalDate if you want to compare offsetted dates

func StryyyymmddLTEQTernary

func StryyyymmddLTEQTernary(_dt1, _dt2, _trueStr, _falseStr string) string

StryyyymmddLTEQTernary is shorthand

func StryyyymmddLTTernary

func StryyyymmddLTTernary(_dt1, _dt2, _trueStr, _falseStr string) string

StryyyymmddLTTernary is shorthand

func Thousands

func Thousands(_num float64) string

Thousands drops fractional part and inserts commas to separate thousands

func Time2YYYYMMDD

func Time2YYYYMMDD(_tt time.Time) int

Time2YYYYMMDD converts time.Time to date string YYYYMMDD

func Timetz2Timetz

func Timetz2Timetz(_time time.Time, _timezone string) time.Time

Timetz2Timetz convert input time to the specified timezone

func ToBool

func ToBool(_str string, _def bool) bool

ToBool converts string to bool, with default

func ToFloat

func ToFloat(_bsl []byte) float64

ToFloat converts string to float, without default

func ToInt

func ToInt(_str string, _def int64) int64

ToInt converts string to int64, with default

func Today

func Today() string

Today is shorthand

func TodayTZ

func TodayTZ(_timezone string) string

TodayTZ returns today in specified timezone

func Toint

func Toint(_str string, _def int) int

Toint converts string to int, with default

func Toint0

func Toint0(_str string) int

Toint0 converts string to int, with default 0

func TwoStrToFloat

func TwoStrToFloat(_bsl1, _bsl2 string) (float64, float64)

TwoStrToFloat converts 2 strings to 2 floats

func UniqueKeys

func UniqueKeys(_strs ...[]string) (strs []string)

UniqueKeys returns array of unique strings within the input string array

func UpdateBoolMap

func UpdateBoolMap(_aset *map[string]bool, _keys []string)

UpdateBoolMap updates the map, setting elements of the slice to true

func UpdateBoolMapFromCsv

func UpdateBoolMapFromCsv(_aset *map[string]bool, _csv, _sep string)

UpdateBoolMapFromCsv updates the map setting elements of the string to true

func UpdateMaxId

func UpdateMaxId(_idmap *map[string]int64, _kk, _newid string) int64

UpdateMaxId updates the max id

func WritableFilename

func WritableFilename(_fname string) (ofname string, ofcode int)

WritableFilename returns information for subsequent writing of the specified file Any compression variants of the file are removed.

func WriteStringToFile

func WriteStringToFile(_str, _fname string)

WriteStringToFile is shorthand

func WriteStringToGzipFile

func WriteStringToGzipFile(_str, _fname string)

WriteStringToGzipFile is shorthand

func YYYYMMDD2M_D_YYYY

func YYYYMMDD2M_D_YYYY(_dt string) string

YYYYMMDD2M_D_YYYY is shorthand

func YYYY_MM_DD2yyyymmdd

func YYYY_MM_DD2yyyymmdd(_bsl []byte) int64

YYYY_MM_DD2yyyymmdd converts bytestring date to int64

func YYYY_MM_DD_HH_MM_SS2yyyymmdd_hhmmss

func YYYY_MM_DD_HH_MM_SS2yyyymmdd_hhmmss(_bsl []byte) (int64, int64)

YYYY_MM_DD_HH_MM_SS2yyyymmdd_hhmmss converts "2020-01-09 16:45:07" format dates to (YYYYMMDD, HHMMSS) string pair

func YYYY_MM_DD_HH_MM_SS_mmm_zz2yyyymmdd_hhmmss_mmm_zz

func YYYY_MM_DD_HH_MM_SS_mmm_zz2yyyymmdd_hhmmss_mmm_zz(_bsl []byte) (int64, int64, int64, int64)

YYYY_MM_DD_HH_MM_SS_mmm_zz2yyyymmdd_hhmmss_mmm_zz converts "2020-01-09 16:45:07.mmm-zz" format dates to (YYYYMMDD, HHMMSS, mmm, zz) string pair Here zz is timezone from pgsql in hours from GMT

func Yyyymmdd2SimpleJulian_Since_1900

func Yyyymmdd2SimpleJulian_Since_1900(_yyyymmdd int64) int64

Yyyymmdd2SimpleJulian_Since_1900 returns simple julian of input date

func ZipFirstFileInfo

func ZipFirstFileInfo(_zipfile string, _verbose bool) (string, string, string, int)

ZipFirstFileInfo returns name, date, time, size

Types

type GzFile

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

GzFile is used to write to regular or gz file, removing existing compression variant first

func OpenGzFile

func OpenGzFile(_fname string) GzFile

OpenGzFile Opens a file for buffered writing, optionally using gzip compression

func (GzFile) Close

func (us GzFile) Close()

Close flushes and closes

func (GzFile) Write

func (us GzFile) Write(pp []byte) (nn int, err error)

func (GzFile) WriteString

func (us GzFile) WriteString(ss string) (nn int, err error)

WriteString writes to the (un)compressed stream

Jump to

Keyboard shortcuts

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