Skip to content

Commit

Permalink
📝 chore: fix maputil test error and re-generate README docs
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jul 24, 2023
1 parent e834938 commit 5e2d478
Show file tree
Hide file tree
Showing 9 changed files with 407 additions and 283 deletions.
296 changes: 177 additions & 119 deletions README.md

Large diffs are not rendered by default.

287 changes: 172 additions & 115 deletions README.zh-CN.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion goutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func FuncName(f any) string {
return goinfo.FuncName(f)
}

// PkgName get current package name. alias of stdutil.PkgName()
// PkgName get current package name. alias of goinfo.PkgName()
//
// Usage:
//
Expand Down
2 changes: 1 addition & 1 deletion internal/gendoc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var (
"json": "JSON Utils",
"cli": "CLI/Console",
"env": "ENV/Environment",
"std": "standard",
"goinfo": "Go Info",
}

// allowLang = map[string]int{
Expand Down
46 changes: 24 additions & 22 deletions internal/template/README.md.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,44 @@

**Basic packages:**

- [`arrutil`](./arrutil): Array/Slice util functions. eg: check, convert, formatting, enum, collections
- [`cliutil`](./cliutil) Command-line util functions. eg: colored print, read input, exec command
- [`envutil`](./envutil) ENV util for current runtime env information. eg: get one, get info, parse var
- [`fmtutil`](./fmtutil) Format data util functions. eg: data, size, time
- [`fsutil`](./fsutil) Filesystem util functions, quick create, read and write file. eg: file and dir check, operate
- [`jsonutil`](./jsonutil) Provide some util functions for quick read, write, encode, decode JSON data.
- [`maputil`](./maputil) Map data util functions. eg: convert, sub-value get, simple merge
- [`mathutil`](./mathutil) Math(int, number) util functions. eg: convert, math calc, random
- [`arrutil`](arrutil): Array/Slice util functions. eg: check, convert, formatting, enum, collections
- [`cliutil`](cliutil) Command-line util functions. eg: colored print, read input, exec command
- [`envutil`](envutil) ENV util for current runtime env information. eg: get one, get info, parse var
- [`fmtutil`](fmtutil) Format data util functions. eg: data, size, time
- [`fsutil`](fsutil) Filesystem util functions, quick create, read and write file. eg: file and dir check, operate
- [`goinfo`](goinfo) provide some standard util functions for go.
- [`jsonutil`](jsonutil) Provide some util functions for quick read, write, encode, decode JSON data.
- [`maputil`](maputil) Map data util functions. eg: convert, sub-value get, simple merge
- [`mathutil`](mathutil) Math(int, number) util functions. eg: convert, math calc, random
- `netutil` Network util functions
- [`reflects`](./reflects) Provide extends reflect util functions.
- [`stdutil`](./stdutil) Provide some commonly std util functions.
- [`structs`](./structs) Provide some extends util functions for struct. eg: tag parse, struct data init
- [`strutil`](./strutil) String util functions. eg: bytes, check, convert, encode, format and more
- [`sysutil`](./sysutil) System util functions. eg: sysenv, exec, user, process
- [`reflects`](reflects) Provide extends reflect util functions.
- [`structs`](structs) Provide some extends util functions for struct. eg: tag parse, struct data init
- [`strutil`](strutil) String util functions. eg: bytes, check, convert, encode, format and more
- [`sysutil`](sysutil) System util functions. eg: sysenv, exec, user, process

**Advance packages:**

- [`cflag`](./cflag): Wraps and extends go `flag.FlagSet` to build simple command line applications
- [`cflag`](cflag): Wraps and extends go `flag.FlagSet` to build simple command line applications
- cli util:
- [cmdline](./cliutil/cmdline) Provide cmdline parse, args build to cmdline
- [`dump`](./dump): GO value printing tool. print slice, map will auto wrap each element and display the call location
- [`errorx`](./errorx) Provide an enhanced error implements for go, allow with stacktrace and wrap another error.
- [`finder`](./fsutil/finder) Provides a simple and convenient filedir lookup function, supports filtering, excluding, matching, ignoring, etc.
- [cmdline](cliutil/cmdline) Provide cmdline parse, args build to cmdline
- [`dump`](dump): GO value printing tool. print slice, map will auto wrap each element and display the call location
- [`errorx`](errorx) Provide an enhanced error implements for go, allow with stacktrace and wrap another error.
- file util:
- [`finder`](fsutil/finder) Provides a simple and convenient filedir lookup function, supports filtering, excluding, matching, ignoring, etc.
- net util:
- [httpreq](netutil/httpreq) An easier-to-use HTTP client that wraps http.Client
- string util:
- [textscan](strutil/textscan) Implemented a parser that quickly scans and analyzes text content. It can be used to parse INI, Properties and other formats
- [textutil](strutil/textutil) Provide some extensions text handle util functions. eg: text replace, etc.
- [syncs](syncs) Provides synchronization primitives util functions.
- system util:
- [clipboard](./sysutil/clipboard) Provide a simple clipboard read and write operations.
- [cmdr](./sysutil/cmdr) Provide for quick build and run a cmd, batch run multi cmd tasks
- [process](./sysutil/process) Provide some process handle util functions.
- [clipboard](sysutil/clipboard) Provide a simple clipboard read and write operations.
- [cmdr](sysutil/cmdr) Provide for quick build and run a cmd, batch run multi cmd tasks
- [process](sysutil/process) Provide some process handle util functions.
- [`testutil`](testutil) Test help util functions. eg: http test, mock ENV value
- [assert](testutil/assert) Provides commonly asserts functions for help testing
- [fakeobj](testutil/fakeobj) provides a fake object for testing. such as fake fs.File, fs.FileInfo, fs.DirEntry etc.
- [`timex`](./timex) Provides an enhanced time.Time implementation. Add more commonly used functional methods
- [`timex`](timex) Provides an enhanced time.Time implementation. Add more commonly used functional methods
- such as: DayStart(), DayAfter(), DayAgo(), DateFormat() and more.

## Go Doc
Expand Down
37 changes: 19 additions & 18 deletions internal/template/README.zh-CN.md.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,34 @@

**基础工具包**

- [`arrutil`](./arrutil) array/slice 相关操作的函数工具包 如:类型转换,元素检查等等
- [`cliutil`](./cliutil) CLI 的一些工具函数包. eg: read input, exec command
- [cmdline](./cliutil/cmdline) 提供 cmdline 解析,args 构建到 cmdline
- [`envutil`](./envutil) ENV 信息获取判断工具包. eg: get one, get info, parse var
- [`fmtutil`](./fmtutil) 格式化数据工具函数 eg:数据size
- [`fsutil`](./fsutil) 文件系统操作相关的工具函数包. eg: file and dir check, operate
- [`jsonutil`](./jsonutil) 一些用于快速读取、写入、编码、解码 JSON 数据的实用函数
- [`maputil`](./maputil) map 相关操作的函数工具包. eg: convert, sub-value get, simple merge
- [`mathutil`](./mathutil) int/number 相关操作的函数工具包. eg: convert, math calc, random
- [`reflects`](./reflects) 提供一些扩展性的反射使用工具函数.
- [`stdutil`](./stdutil) 提供一些常用的 std util 函数。
- [`structs`](./structs) 为 struct 提供一些扩展 util 函数。 eg: tag parse, struct data
- [`strutil`](./strutil) string 相关操作的函数工具包. eg: bytes, check, convert, encode, format and more
- [`sysutil`](./sysutil) system 相关操作的函数工具包. eg: sysenv, exec, user, process
- [`arrutil`](arrutil) array/slice 相关操作的函数工具包 如:类型转换,元素检查等等
- [`cliutil`](cliutil) CLI 的一些工具函数包. eg: read input, exec command
- [cmdline](cliutil/cmdline) 提供 cmdline 解析,args 构建到 cmdline
- [`envutil`](envutil) ENV 信息获取判断工具包. eg: get one, get info, parse var
- [`fmtutil`](fmtutil) 格式化数据工具函数 eg:数据size
- [`fsutil`](fsutil) 文件系统操作相关的工具函数包. eg: file and dir check, operate
- [`goinfo`](goinfo) 提供一些与Go info, runtime 相关的工具函数
- [`jsonutil`](jsonutil) 一些用于快速读取、写入、编码、解码 JSON 数据的实用函数。
- [`maputil`](maputil) map 相关操作的函数工具包. eg: convert, sub-value get, simple merge
- [`mathutil`](mathutil) int/number 相关操作的函数工具包. eg: convert, math calc, random
- [`reflects`](reflects) 提供一些扩展性的反射使用工具函数.
- [`structs`](structs) 为 struct 提供一些扩展 util 函数。 eg: tag parse, struct data
- [`strutil`](strutil) string 相关操作的函数工具包. eg: bytes, check, convert, encode, format and more
- [`sysutil`](sysutil) system 相关操作的函数工具包. eg: sysenv, exec, user, process

**扩展工具包**

- [`cflag`](./cflag): 包装和扩展 go `flag.FlagSet` 以方便快速的构建简单的命令行应用程序
- [`dump`](./dump) GO变量打印工具,打印 slice, map 会自动换行显示每个元素,同时会显示打印调用位置
- [`errorx`](./errorx) 为 go 提供增强的错误实现,允许带有堆栈跟踪信息和包装另一个错误。
- [`finder`](./fsutil/finder) 提供简单方便的file/dir查找功能,支持过滤、排除、匹配、忽略等。
- netutil:
- netutil 子包:
- `netutil/httpreq` 包装 http.Client 实现的更加易于使用的HTTP客户端
- strutil:
- strutil 子包:
- [textscan](strutil/textscan) 实现了一个快速扫描和分析文本内容的解析器. 可用于解析 INI, Properties 等格式内容
- [textutil](strutil/textutil) 提供一些常用的扩展文本处理功能函数。
- sysutil:
- [syncs](syncs) 提供一些同步、协程、信号相关的工具函数.
- sysutil 子包:
- [clipboard](sysutil/clipboard) 提供简单的剪贴板读写操作工具库
- [cmdr](sysutil/cmdr) 提供快速构建和运行一个cmd,批量运行多个cmd任务
- [process](sysutil/process) 提供一些进程操作相关的实用功能。
Expand All @@ -48,7 +49,7 @@
- [fakeobj](testutil/fakeobj) 提供一些接口的假的实现,用于模拟测试. 例如 fs.File, fs.FileInfo, fs.DirEntry 等等.
- [`timex`](timex) 提供增强的 time.Time 实现。添加更多常用的功能方法
- 提供类似 `Y-m-d H:i:s` 的日期时间格式解析处理
- 例如: DayStart(), DayAfter(), DayAgo(), DateFormat() 等等
- 常用时间方法。例如: DayStart(), DayAfter(), DayAgo(), DateFormat() 等等

## GoDoc

Expand Down
14 changes: 7 additions & 7 deletions maputil/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,18 @@ func GetFromAny(path string, data any) (val any, ok bool) {
if data == nil {
return nil, false
}

keys := strings.Split(path, ".")
if len(keys) == 0 {
if len(path) == 0 {
return data, true
}

return getByPathKeys(data, keys)
return getByPathKeys(data, strings.Split(path, "."))
}

// GetByPath get value by key path from a map(map[string]any). eg "top" "top.sub"
func GetByPath(path string, mp map[string]any) (val any, ok bool) {
if len(path) == 0 {
return mp, true
}
if val, ok := mp[path]; ok {
return val, true
}
Expand All @@ -52,9 +53,8 @@ func GetByPath(path string, mp map[string]any) (val any, ok bool) {
return nil, false
}

// has sub key. eg. "top.sub"
keys := strings.Split(path, ".")
return GetByPathKeys(mp, keys)
// key is path. eg: "top.sub"
return GetByPathKeys(mp, strings.Split(path, "."))
}

// GetByPathKeys get value by path keys from a map(map[string]any). eg "top" "top.sub"
Expand Down
4 changes: 4 additions & 0 deletions maputil/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ func TestGetByPath(t *testing.T) {
v, ok := maputil.GetByPath("mlMp.*.names.1", mp)
assert.True(t, ok)
assert.Eq(t, []any{"abc", "def"}, v)

v, ok = maputil.GetByPath("", mp)
assert.True(t, ok)
assert.NotEmpty(t, v)
}

var mlMp = map[string]any{
Expand Down
2 changes: 2 additions & 0 deletions syncs/syncs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package syncs provides synchronization primitives util functions.
package syncs

0 comments on commit 5e2d478

Please sign in to comment.