|
7 | 7 | [](https://coveralls.io/github/gookit/goutil?branch=master) |
8 | 8 | [](https://pkg.go.dev/github.com/gookit/goutil) |
9 | 9 |
|
10 | | -💪 Useful utils(**900+**) package for the Go: int, string, array/slice, map, error, time, format, CLI, ENV, filesystem, system, testing and more. |
| 10 | +💪 Useful utils(**900+**) package for the Go: int, string, array/slice, map, struct, reflect, error, time, format, CLI, ENV, filesystem, system, testing and more. |
11 | 11 |
|
12 | 12 | > **[中文说明](README.zh-CN.md)** |
13 | 13 |
|
@@ -109,6 +109,8 @@ dump.Print(somevar, somevar2, ...) |
109 | 109 |
|
110 | 110 | > Package `github.com/gookit/goutil/arrutil` |
111 | 111 |
|
| 112 | +<details><summary>Click to see functions 👈</summary> |
| 113 | + |
112 | 114 | ```go |
113 | 115 | // source at arrutil/arrutil.go |
114 | 116 | func GetRandomOne[T any](arr []T) T |
@@ -192,6 +194,8 @@ func StringsMap(ss []string, mapFn func(s string) string) []string |
192 | 194 | func TrimStrings(ss []string, cutSet ...string) []string |
193 | 195 | ``` |
194 | 196 |
|
| 197 | +</details> |
| 198 | + |
195 | 199 | #### ArrUtil Usage |
196 | 200 |
|
197 | 201 | **check value**: |
@@ -485,6 +489,8 @@ Preview: |
485 | 489 |
|
486 | 490 | > Package `github.com/gookit/goutil/envutil` |
487 | 491 |
|
| 492 | +<details><summary>Click to see functions 👈</summary> |
| 493 | + |
488 | 494 | ```go |
489 | 495 | // source at envutil/envutil.go |
490 | 496 | func VarReplace(s string) string |
@@ -529,6 +535,8 @@ func LoadText(text string) |
529 | 535 | func LoadString(line string) bool |
530 | 536 | ``` |
531 | 537 |
|
| 538 | +</details> |
| 539 | + |
532 | 540 | #### ENV Util Usage |
533 | 541 |
|
534 | 542 | **helper functions:** |
@@ -693,6 +701,8 @@ runtime.goexit() |
693 | 701 |
|
694 | 702 | Package `fsutil` Filesystem util functions: quick check, create, read and write file. eg: file and dir check, operate |
695 | 703 |
|
| 704 | +<details><summary>Click to see functions 👈</summary> |
| 705 | +
|
696 | 706 | ```go |
697 | 707 | // source at fsutil/check.go |
698 | 708 | func PathExists(path string) bool |
@@ -826,6 +836,8 @@ func UpdateContents(filePath string, handleFn func(bs []byte) []byte) error |
826 | 836 | func CreateSymlink(target, linkPath string) error |
827 | 837 | ``` |
828 | 838 |
|
| 839 | +</details> |
| 840 | +
|
829 | 841 |
|
830 | 842 | #### FsUtil Usage |
831 | 843 |
|
@@ -892,6 +904,8 @@ func StripComments(src string) string |
892 | 904 |
|
893 | 905 | > Package `github.com/gookit/goutil/maputil` |
894 | 906 |
|
| 907 | +<details><summary>Click to see functions 👈</summary> |
| 908 | +
|
895 | 909 | ```go |
896 | 910 | // source at maputil/check.go |
897 | 911 | func HasKey(mp, key any) (ok bool) |
@@ -949,12 +963,16 @@ func SetByPath(mp *map[string]any, path string, val any) error |
949 | 963 | func SetByKeys(mp *map[string]any, keys []string, val any) (err error) |
950 | 964 | ``` |
951 | 965 |
|
| 966 | +</details> |
| 967 | +
|
952 | 968 |
|
953 | 969 | ### Math/Number |
954 | 970 |
|
955 | 971 | > Package `github.com/gookit/goutil/mathutil` |
956 | 972 |
|
957 | 973 | Package `mathutil` provide math(int, number) util functions. eg: convert, math calc, random |
| 974 | +<details><summary>Click to see functions 👈</summary> |
| 975 | +
|
958 | 976 | ```go |
959 | 977 | // source at mathutil/calc.go |
960 | 978 | func Abs[T comdef.Int](val T) T |
@@ -1075,11 +1093,14 @@ func RandIntWithSeed(min, max int, seed int64) int |
1075 | 1093 | func RandomIntWithSeed(min, max int, seed int64) int |
1076 | 1094 | ``` |
1077 | 1095 |
|
| 1096 | +</details> |
| 1097 | +
|
1078 | 1098 |
|
1079 | 1099 | ### Reflects |
1080 | 1100 |
|
1081 | 1101 | > Package `github.com/gookit/goutil/reflects` |
1082 | 1102 |
|
| 1103 | +Package `reflects` Provide extends reflection util functions. eg: check, convert, value set, etc. |
1083 | 1104 | <details><summary>Click to see functions 👈</summary> |
1084 | 1105 |
|
1085 | 1106 | ```go |
@@ -1155,6 +1176,7 @@ func ValueOf(v any) Value |
1155 | 1176 |
|
1156 | 1177 | > Package `github.com/gookit/goutil/structs` |
1157 | 1178 |
|
| 1179 | +Package `structs` Provide some extends util functions for struct. eg: tag parse, struct init, value set/get |
1158 | 1180 | <details><summary>Click to see functions 👈</summary> |
1159 | 1181 |
|
1160 | 1182 | ```go |
@@ -1493,6 +1515,8 @@ func SubstrCount(s, substr string, params ...uint64) (int, error) |
1493 | 1515 |
|
1494 | 1516 | > Package `github.com/gookit/goutil/sysutil` |
1495 | 1517 |
|
| 1518 | +<details><summary>Click to see functions 👈</summary> |
| 1519 | +
|
1496 | 1520 | ```go |
1497 | 1521 | // source at sysutil/exec.go |
1498 | 1522 | func NewCmd(bin string, args ...string) *cmdr.Cmd |
@@ -1569,11 +1593,15 @@ func ChangeUserUidGid(newUID int, newGid int) error |
1569 | 1593 | func ChangeUserUIDGid(newUID int, newGid int) (err error) |
1570 | 1594 | ``` |
1571 | 1595 |
|
| 1596 | +</details> |
| 1597 | +
|
1572 | 1598 |
|
1573 | 1599 | ### Testing Utils |
1574 | 1600 |
|
1575 | 1601 | > Package `github.com/gookit/goutil/testutil` |
1576 | 1602 |
|
| 1603 | +<details><summary>Click to see functions 👈</summary> |
| 1604 | +
|
1577 | 1605 | ```go |
1578 | 1606 | // source at testutil/buffer.go |
1579 | 1607 | func NewBuffer() *byteutil.Buffer |
@@ -1613,12 +1641,16 @@ func NewTestWriter() *TestWriter |
1613 | 1641 | func NewDirEnt(fPath string, isDir ...bool) *fakeobj.DirEntry |
1614 | 1642 | ``` |
1615 | 1643 |
|
| 1644 | +</details> |
| 1645 | +
|
1616 | 1646 |
|
1617 | 1647 | ### Timex |
1618 | 1648 |
|
1619 | 1649 | > Package `github.com/gookit/goutil/timex` |
1620 | 1650 |
|
1621 | | -Provides an enhanced time.Time implementation, and add more commonly used functional methods. |
| 1651 | +Provides an enhanced `time.Time` implementation, and add more commonly used functional methods. |
| 1652 | +<details><summary>Click to see functions 👈</summary> |
| 1653 | +
|
1622 | 1654 | ```go |
1623 | 1655 | // source at timex/check.go |
1624 | 1656 | func IsDuration(s string) bool |
@@ -1683,6 +1715,7 @@ func FormatUnixBy(sec int64, layout string) string |
1683 | 1715 | func FormatUnixByTpl(sec int64, template ...string) string |
1684 | 1716 | ``` |
1685 | 1717 |
|
| 1718 | +</details> |
1686 | 1719 | #### Timex Usage |
1687 | 1720 |
|
1688 | 1721 | **Create timex instance** |
|
0 commit comments