need more detailed usage? please refer test cases.
DoWithWorker() |
iterate chan and do with workers |
Every() |
run func with interval |
After() |
run function with delay |
Async() ,Async2() |
run function with goroutine and get result asynchronous |
ReadJSON() |
decode json to type |
WriteJSON() |
encode json towriter |
ReadXML() |
decode xml to type |
WriteXML() |
encode json towriter |
ReadYAML() |
decode yaml to type |
WriteYAML() |
encode json towriter |
SetBits() |
|
ClearBits() |
|
IsContextDone() |
return true if context is done |
WithTimeout() |
run fn() with timeout context |
Must(error) |
panic if error not nil |
NewPool[T]() |
sync.Pool with generics |
Abs() |
AtoiDef() |
strconv.Atoi() with default value |
ParseBoolDef() |
strconv.ParseBool() with default value |
ParseIntDef() |
strconv.ParseInt() with default value |
ParseDateTime() |
parse string to time for well known layouts |
TimeWithLayout |
time.Time with layouts |
RFC1123ZTime |
Mon, 02 Jan 2006 15:04:05 -0700 |
RFC3339Time |
2006-01-02T15:04:05Z07:00 |
run command and output to stdin/stdout
exc := Exec("ls", "-al")
err := exc.Do(context.Background())
require.NoError(t, err)
run command and get output
exc := Exec("ls", "-al")
output, err := exc.Output(context.Background())
require.NoError(t, err)
require.Contains(t, string(output), "README.md")
IfThen(true, func() { fmt.Printf("true\n") })
// true
IfThen(true, func() { fmt.Printf("true\n") }, func() { fmt.Printf("false\n") })
// true
IfThen(false, func() { fmt.Printf("true\n") }, func() { fmt.Printf("false\n") })
// false
IfThen(false, func() { fmt.Printf("true\n") }, func() { fmt.Printf("false\n") }, func() { fmt.Printf("false\n") })
// false
b := RandomByte(10)
// hex.EncodeToString(b) = "4d46ef2f87b8191daf58"
s := RandomString(10)
// s = "$c&I$#LR3Y"
s := RandomStringWith(10, []rune("abcdefg"))
// s = "bbffedabda"
func doSomething() {
defer goxp.Timer("doSomething()")()
time.Sleep(500 * time.Millisecond)
}
doSomething()
// time takes 500.505063ms: doSomething()
Tuple2 , Tuple3 |
Pack() and Unpack() |
T2 ,T3 |
construct tuple with element |
- chanx -
chan
extensions - cobrax -
cobra
andviper
utility functions - cryptox - encrypt/ decrypt functions
- errors - errors with stack tracd
- fixtures - useful fixture functions for test
- flags - cobra & viper make easy
- fx - experimental: some functional functions by
iter.Seq
- fx/gen - experimental: generator
- httptest - test http sever make easy
- iterx -
iter.Seq
extensions - log - simple log powered by zap
- mapx - map extesions
- requests - simple http client
- retry - retrier with backoff
- services - simple service framework
- sets - Set type
- slicex - slice extensions
- slug - uuid to slug
- testx - unit test utility functions
- validate - validator make easy
- x509x - x509 utility functions