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 Confirm(query string, positiveChoices, negativeChoices []string, negativeAction func())
- 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 GreenText(format string, a ...interface{})
- func InParam(ins []string) string
- func Int2Str(i int) 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{}) (out string, err 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 RedText(format string, a ...interface{})
- 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 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
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 ¶ added in v1.2.1
BeginningOfMonth returns the first date of a month where t belongs to.
func BeginningOfThisMonth ¶ added in v1.2.1
BeginningOfThisMonth returns the first date of this month.
func BeginningOfThisWeek ¶ added in v1.2.0
BeginningOfThisWeek returns the beginning date of this week.
func BeginningOfThisYear ¶ added in v1.2.1
BeginningOfThisYear returns the first date of this year.
func BeginningOfWeek ¶ added in v1.2.0
BeginningOfWeek return the first date of the week where t belongs to.
func BeginningOfYear ¶ added in v1.2.1
BeginningOfYear returns the first date of a year where t belongs to.
func Confirm ¶ added in v1.2.1
Confirm force input string must be in positiveChoices or negativeChoices, if false choice is selected, negative action will be invoked. This function can be useful that if you want user must make a choice before doing anything further.
func ContainsAnyInt ¶ added in v1.2.0
ContainsAnyInt return true if arr contains any value in vals.
func ContainsAnyIntFunc ¶ added in v1.2.0
ContainsAnyIntFunc return true if arr contains any value v when f(v) evalutes to true.
func ContainsAnyStr ¶ added in v1.2.0
ContainsAnyStr return true if arr contains any value in vals.
func ContainsAnyStrFunc ¶ added in v1.2.0
ContainsAnyStrFunc return true if arr contains any value v when f(v) evalutes to true.
func ContainsInt ¶ added in v1.2.0
ContainsInt returns true if arr contains val.
func ContainsStr ¶ added in v1.2.0
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 ¶ added in v1.2.1
EndOfThisMonth returns the last date of this month.
func EndOfThisYear ¶ added in v1.2.1
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 ¶ added in v1.2.0
Escape the sql to prevent sql injection. Simply a copy from https://gist.github.com/siddontang/8875771
func GreenText ¶ added in v1.2.1
func GreenText(format string, a ...interface{})
GreenText prints green colored text.
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 RedText ¶ added in v1.2.1
func RedText(format string, a ...interface{})
RedText prints red colored text.
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 ¶ added in v1.2.1
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 ¶ added in v1.2.1
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 ¶ added in v1.2.1
ToInt convert string and any other int/float types to int. Warning: the result my be truncated if number overflows int.
func ToIntWithDefault ¶ added in v1.2.1
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.
Types ¶
This section is empty.