Documentation ¶
Index ¶
- Constants
- func BeginningOfDate(t time.Time) time.Time
- func BeginningOfMonth(t time.Time) time.Time
- func BeginningOfThisMonth() time.Time
- func BeginningOfThisWeek() time.Time
- func BeginningOfThisYear() time.Time
- func BeginningOfWeek(t time.Time) time.Time
- func BeginningOfYear(t time.Time) time.Time
- func ContainsAnyInt(arr []int, vals ...int) bool
- func ContainsAnyIntFunc(arr []int, f func(int) bool) bool
- func ContainsAnyStr(arr []string, vals ...string) bool
- func ContainsAnyStrFunc(arr []string, f func(string) bool) bool
- func ContainsInt(arr []int, val int) bool
- func ContainsStr(arr []string, val string) bool
- func DaysAfter(t time.Time, days int) time.Time
- func DaysAgo(t time.Time, days int) time.Time
- func DaysBetween(startTime, endTime time.Time) int
- func DefaultIfBlank(str, defaultStr string) string
- func DefaultIfEmpty(str, defaultStr string) string
- func EndOfDate(t time.Time) time.Time
- func EndOfThisMonth() time.Time
- func EndOfThisYear() time.Time
- func EndingOfDate(t time.Time) time.Time
- func Escape(sql string) string
- func FmtTime(time time.Time, layout string) (string, error)
- func Grep(src, val string, config *GrepConfig) []string
- func InParam(ins []string) string
- func Int2Str(i int) string
- func Int64ToStr(i int64) string
- func IsAnyBlank(strList ...string) bool
- func IsBlank(str string) bool
- func IsDir(path string) bool
- func IsEmpty(str string) bool
- func IsEqualsAny(val string, vals ...string) bool
- func IsFileExists(filepath string) bool
- func IsNotBlank(str string) bool
- func IsNotEmpty(str string) bool
- func IsRegular(path string) bool
- func LastMonth() time.Time
- func LastWeek() time.Time
- func LastYear() time.Time
- func LeftPad(str string, size int, padChar rune) string
- func Local(localCmd string, paras ...interface{}) (string, error)
- func MaxInt() int
- func MustFmtTime(time time.Time, layout string) string
- func MustParseLocaltime(toParseTime, layout string) time.Time
- func ParseLocaltime(toParseTime, layout string) (time.Time, error)
- func RandDuration(lower, upper, timeUnitType int) time.Duration
- func ReadLine(filepath string, handler func(line string, index uint64)) error
- func RemoveTrailingSlash(path string) string
- func Reverse(s string) string
- func ReversePreservingCombiningCharacters(s string) string
- func RightPad(str string, size int, padChar rune) string
- func RtLocal(localCmd string, lineHandler func(line string, lineType int8), ...) error
- func Str2Int(str string) (int, error)
- func Str2Int64(str string) (int64, error)
- func Substring(str string, i, j int) string
- func SumInt(a ...int) int
- func SumIntSlice(s []int) int
- func Tar(tgzPath, targetPath string) error
- func ToInt(v interface{}) (int, error)
- func ToIntWithDefault(v interface{}, defVal int) int
- func Today() time.Time
- func Tomorrow() time.Time
- func Trim(str string) string
- func UnTar(tgzPath, targetPath string) error
- func Yesterday() time.Time
- type GrepConfig
Constants ¶
const ( // TimeUnitTypeSecond as second TimeUnitTypeSecond int = 0 // TimeUnitTypeMinute as minute TimeUnitTypeMinute int = 1 // TimeUnitTypeHour as hour TimeUnitTypeHour int = 2 )
const ( // TypeStdout is type of stdout TypeStdout = 0 // TypeStderr is type of stderr TypeStderr = 1 )
Variables ¶
This section is empty.
Functions ¶
func BeginningOfDate ¶
BeginningOfDate returns the beginning date of a time.
func BeginningOfMonth ¶
BeginningOfMonth returns the first date of a month where t belongs to.
func BeginningOfThisMonth ¶
BeginningOfThisMonth returns the first date of this month.
func BeginningOfThisWeek ¶
BeginningOfThisWeek returns the beginning date of this week.
func BeginningOfThisYear ¶
BeginningOfThisYear returns the first date of this year.
func BeginningOfWeek ¶
BeginningOfWeek return the first date of the week where t belongs to.
func BeginningOfYear ¶
BeginningOfYear returns the first date of a year where t belongs to.
func ContainsAnyInt ¶
ContainsAnyInt return true if arr contains any value in vals.
func ContainsAnyIntFunc ¶
ContainsAnyIntFunc return true if arr contains any value v when f(v) evalutes to true.
func ContainsAnyStr ¶
ContainsAnyStr return true if arr contains any value in vals.
func ContainsAnyStrFunc ¶
ContainsAnyStrFunc return true if arr contains any value v when f(v) evalutes to true.
func ContainsInt ¶
ContainsInt returns true if arr contains val.
func ContainsStr ¶
ContainsStr returns true if arr contains val.
func DaysBetween ¶
DaysBetween calc days between two days. goutils.DaysBetween(goutils.Yesterday(), goutils.Today()) = 1 goutils.DaysBetween(goutils.Today(), goutils.Yesterday()) = -1
func DefaultIfBlank ¶
DefaultIfBlank Returns either the passed in string, or if the string is whitespace, empty (""), the value of default string.
func DefaultIfEmpty ¶
DefaultIfEmpty Returns either the passed in string, or if the string is empty (""), the value of default string.
func EndOfThisMonth ¶
EndOfThisMonth returns the last date of this month.
func EndOfThisYear ¶
EndOfThisYear returns the last date of this year.
func EndingOfDate ¶
EndingOfDate returns the ending nano of a date where t belongs to. Deprecated: Use EndOfDate instead.
func Escape ¶
Escape the sql to prevent sql injection. Simply a copy from https://gist.github.com/siddontang/8875771
func Grep ¶ added in v1.0.9
func Grep(src, val string, config *GrepConfig) []string
grep val from src, val cannot contain line break. from start means if any match found, the first match will starting from the very start line.
func IsAnyBlank ¶
IsAnyBlank checks if any one of the CharSequences are blank ("") or whitespace only.
func IsEqualsAny ¶
IsEqualsAny tests whether a string equals any string provided.
func IsFileExists ¶
IsFileExists tests existence of specified file.
func IsNotBlank ¶
IsNotBlank Checks if a string is not empty (""), not null and not whitespace only.
func LeftPad ¶
LeftPad pad a String with a specified character on the left. WARNING: string to pad should be uft8-encoded!
goutils.LeftPad("", 3, 'z') = "zzz" goutils.LeftPad("bat", 3, 'z') = "bat" goutils.LeftPad("bat", 5, 'z') = "zzbat" goutils.LeftPad("bat", 1, 'z') = "bat" goutils.LeftPad("bat", -1, 'z') = "bat"
func Local ¶
Local run the command in localhost https://studygolang.com/articles/4004 <- run shell command and read output line by line https://studygolang.com/articles/7767 <- run command without known args
func MustFmtTime ¶
MustFmtTime format time by specified layout, will panic if layout is invalid.
func MustParseLocaltime ¶
MustParseLocaltime time with zone set to local, will panic if layout specified is invalid. parsable layout can be [-datetime|-datetime-|-datetime--|-date|-date-|-date--|time|time-|time--] and any other layout format that can pass to time.ParseInLocation
func ParseLocaltime ¶
ParseLocaltime time with zone set to local. parsable layout can be [-datetime|-datetime-|-datetime--|-date|-date-|-date--|time|time-|time--] and any other layout format that can pass to time.ParseInLocation
func RandDuration ¶
RandDuration generate pseudo time duration between lower and upper with lower and upper bound inclusively.
func RemoveTrailingSlash ¶
RemoveTrailingSlash remove the last slash of a path except the root path.
func Reverse ¶
Reverse reverse a string. WARNING: This does not work with combining characters. check https://stackoverflow.com/questions/1752414/how-to-reverse-a-string-in-go for more stories.
goutils.Reverse("hello") = "olleh"
func ReversePreservingCombiningCharacters ¶
ReversePreservingCombiningCharacters reverse a string preserving combining characters. The implementation is copied from http://rosettacode.org/wiki/Reverse_a_string#Go goutils.ReversePreservingCombiningCharacters("The quick bròwn 狐 jumped over the lazy 犬") = "犬 yzal eht revo depmuj 狐 nwòrb kciuq ehT"
func RightPad ¶
RightPad right pad a String with a specified character. WARNING: string to pad should be uft8-encoded!
goutils.RightPad("", 3, 'z') = "zzz" goutils.RightPad("bat", 3, 'z') = "bat" goutils.RightPad("bat", 5, 'z') = "batzz" goutils.RightPad("bat", 1, 'z') = "bat" goutils.RightPad("bat", -1, 'z') = "bat"
func RtLocal ¶
func RtLocal(localCmd string, lineHandler func(line string, lineType int8), paras ...interface{}) error
RtLocal run the command in localhost and get command output realtime.
func SumInt ¶
SumInt do summary of all int paras.
Warning: if no para provided, zero will be returned. this func does not care about overflow, using at own risk.
func SumIntSlice ¶
SumIntSlice do summary of the int slice.
Warning: if empty or nil slice is provided, zero will be returned. this func does not care about overflow, using at own risk.
func Tar ¶
Tar pack the targetPath and put tarball to tgzPath, targetPath and tgzPath should both the absolute path.
func ToInt ¶
ToInt convert string and any other int/float types to int. Warning: the result my be truncated if number overflows int.
func ToIntWithDefault ¶
ToIntWithDefault tries to convert string and any other int types to int, return a default value provided if error occurs. Warning: the result my be truncated if number overflows int.
func Trim ¶
Trim returns a slice of the string s, with all leading and trailing white space removed, as defined by Unicode.