mirror of
https://github.com/duke-git/lancet.git
synced 2025-09-26 19:41:20 +08:00
doc: update doc for RandNumberOfLength and GetExeOrDllVersion
This commit is contained in:
@@ -52,7 +52,8 @@ import (
|
|||||||
- [ReadFile](#ReadFile)
|
- [ReadFile](#ReadFile)
|
||||||
- [ChunkRead](#ChunkRead)
|
- [ChunkRead](#ChunkRead)
|
||||||
- [ParallelChunkRead](#ParallelChunkRead)
|
- [ParallelChunkRead](#ParallelChunkRead)
|
||||||
- [GetVersion](#Version)
|
- [GetExeOrDllVersion](#GetExeOrDllVersion)
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
## 文档
|
## 文档
|
||||||
@@ -1077,17 +1078,17 @@ func main() {
|
|||||||
// 2
|
// 2
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
### <span id="Version">GetExeDllVersion</span>
|
### <span id="GetExeOrDllVersion">GetExeOrDllVersion</span>
|
||||||
|
|
||||||
<p>返回exe,dll文件版本号(仅Window平台).</p>
|
<p>返回exe,dll文件版本号(仅Window平台).</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func GetExeDllVersion(filePath string) (string, error)
|
func GetExeOrDllVersion(filePath string) (string, error)
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/s_Tl7lZoAaY)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1098,7 +1099,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
v, err := fileutil.GetExeDllVersion(`C:\Program Files\Tencent\WeChat\WeChat.exe`)
|
v, err := fileutil.GetExeOrDllVersion(`C:\Program Files\Tencent\WeChat\WeChat.exe`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@@ -40,7 +40,7 @@ import (
|
|||||||
- [RandStringSlice](#RandStringSlice)
|
- [RandStringSlice](#RandStringSlice)
|
||||||
- [RandBool](#RandBool)
|
- [RandBool](#RandBool)
|
||||||
- [RandBoolSlice](#RandBoolSlice)
|
- [RandBoolSlice](#RandBoolSlice)
|
||||||
- [RandNumLen](#RandNumLen)
|
- [RandNumberOfLength](#RandNumberOfLength)
|
||||||
|
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
@@ -524,17 +524,17 @@ func main() {
|
|||||||
fmt.Println(result) // [true false] (random)
|
fmt.Println(result) // [true false] (random)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
### <span id="RandNumLen">RandNumLen</span>
|
### <span id="RandNumberOfLength">RandNumberOfLength</span>
|
||||||
|
|
||||||
<p>生成指定长度的随机数</p>
|
<p>生成指定长度的随机数</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func RandNumLen(len int) int
|
func RandNumberOfLength(len int) int
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>实例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/o-VSjPjnILI)</span></b>
|
<b>实例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -545,7 +545,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
i := random.RandNumLen(2)
|
i := random.RandNumberOfLength(2)
|
||||||
fmt.Println(i)
|
fmt.Println(i) // 21 (random number of length 2)
|
||||||
}
|
}
|
||||||
```
|
```
|
@@ -52,6 +52,7 @@ import (
|
|||||||
- [ReadFile](#ReadFile)
|
- [ReadFile](#ReadFile)
|
||||||
- [ChunkRead](#ChunkRead)
|
- [ChunkRead](#ChunkRead)
|
||||||
- [ParallelChunkRead](#ParallelChunkRead)
|
- [ParallelChunkRead](#ParallelChunkRead)
|
||||||
|
- [GetExeOrDllVersion](#GetExeOrDllVersion)
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
@@ -1074,4 +1075,37 @@ func main() {
|
|||||||
// Jim,21,male
|
// Jim,21,male
|
||||||
// 2
|
// 2
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="GetExeOrDllVersion">GetExeOrDllVersion</span>
|
||||||
|
|
||||||
|
<p>Get the version of exe or dll file on windows.</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func GetExeOrDllVersion(filePath string) (string, error)
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/fileutil"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
v, err := fileutil.GetExeOrDllVersion(`C:\Program Files\Tencent\WeChat\WeChat.exe`)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(v)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// 3.9.10.19
|
||||||
|
}
|
||||||
```
|
```
|
@@ -40,6 +40,7 @@ import (
|
|||||||
- [RandStringSlice](#RandStringSlice)
|
- [RandStringSlice](#RandStringSlice)
|
||||||
- [RandBool](#RandBool)
|
- [RandBool](#RandBool)
|
||||||
- [RandBoolSlice](#RandBoolSlice)
|
- [RandBoolSlice](#RandBoolSlice)
|
||||||
|
- [RandNumberOfLength](#RandNumberOfLength)
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
@@ -523,4 +524,30 @@ func main() {
|
|||||||
result := random.RandBoolSlice(2)
|
result := random.RandBoolSlice(2)
|
||||||
fmt.Println(result) // [true false] (random)
|
fmt.Println(result) // [true false] (random)
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="RandNumberOfLength">RandNumberOfLength</span>
|
||||||
|
|
||||||
|
<p>Generates a random int number of specified length.</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func RandNumberOfLength(len int) int
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Signature:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/random"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
i := random.RandNumberOfLength(2)
|
||||||
|
fmt.Println(i) // 21 (random number of length 2)
|
||||||
|
}
|
||||||
```
|
```
|
@@ -25,8 +25,9 @@ type tagVS_FIXEDFILEINFO struct {
|
|||||||
FileDateLS uint32
|
FileDateLS uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetExeDllVersion 获取exe或dll文件的版本信息
|
// GetExeOrDllVersion get the version of exe or dll file on windows.
|
||||||
func GetExeDllVersion(filePath string) (string, error) {
|
// Play: todo
|
||||||
|
func GetExeOrDllVersion(filePath string) (string, error) {
|
||||||
// 加载系统dll
|
// 加载系统dll
|
||||||
versionDLL := syscall.NewLazyDLL("version.dll")
|
versionDLL := syscall.NewLazyDLL("version.dll")
|
||||||
getFileVersionInfoSize := versionDLL.NewProc("GetFileVersionInfoSizeW")
|
getFileVersionInfoSize := versionDLL.NewProc("GetFileVersionInfoSizeW")
|
||||||
@@ -77,5 +78,6 @@ func GetExeDllVersion(filePath string) (string, error) {
|
|||||||
minor := fixedInfo.FileVersionMS & 0xFFFF
|
minor := fixedInfo.FileVersionMS & 0xFFFF
|
||||||
build := fixedInfo.FileVersionLS >> 16
|
build := fixedInfo.FileVersionLS >> 16
|
||||||
revision := fixedInfo.FileVersionLS & 0xFFFF
|
revision := fixedInfo.FileVersionLS & 0xFFFF
|
||||||
|
|
||||||
return fmt.Sprintf("%d.%d.%d.%d", major, minor, build, revision), nil
|
return fmt.Sprintf("%d.%d.%d.%d", major, minor, build, revision), nil
|
||||||
}
|
}
|
||||||
|
@@ -4,8 +4,8 @@ package fileutil
|
|||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestGetExeDllVersion(t *testing.T) {
|
func TestGetExeOrDllVersion(t *testing.T) {
|
||||||
v, err := GetExeDllVersion(`C:\Windows\System32\cmd.exe`)
|
v, err := GetExeOrDllVersion(`C:\Windows\System32\cmd.exe`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
1
go.mod
1
go.mod
@@ -4,6 +4,5 @@ go 1.18
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
golang.org/x/exp v0.0.0-20221208152030-732eee02a75a
|
golang.org/x/exp v0.0.0-20221208152030-732eee02a75a
|
||||||
golang.org/x/sys v0.5.0
|
|
||||||
golang.org/x/text v0.9.0
|
golang.org/x/text v0.9.0
|
||||||
)
|
)
|
||||||
|
2
go.sum
2
go.sum
@@ -1,6 +1,4 @@
|
|||||||
golang.org/x/exp v0.0.0-20221208152030-732eee02a75a h1:4iLhBPcpqFmylhnkbY3W0ONLUYYkDAW9xMFLfxgsvCw=
|
golang.org/x/exp v0.0.0-20221208152030-732eee02a75a h1:4iLhBPcpqFmylhnkbY3W0ONLUYYkDAW9xMFLfxgsvCw=
|
||||||
golang.org/x/exp v0.0.0-20221208152030-732eee02a75a/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
|
golang.org/x/exp v0.0.0-20221208152030-732eee02a75a/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
|
||||||
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
|
|
||||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
|
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
|
||||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||||
|
@@ -328,11 +328,12 @@ func UUIdV4() (string, error) {
|
|||||||
return fmt.Sprintf("%x-%x-%x-%x-%x", uuid[0:4], uuid[4:6], uuid[6:8], uuid[8:10], uuid[10:]), nil
|
return fmt.Sprintf("%x-%x-%x-%x-%x", uuid[0:4], uuid[4:6], uuid[6:8], uuid[8:10], uuid[10:]), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RandNumLen 生成一个长度为len的随机数
|
// RandNumberOfLength 生成一个长度为len的随机数
|
||||||
// Play: https://go.dev/play/p/jpIalcD5rMo
|
// Play: todo
|
||||||
func RandNumLen(len int) int {
|
func RandNumberOfLength(len int) int {
|
||||||
m := int(math.Pow10(len) - 1)
|
m := int(math.Pow10(len) - 1)
|
||||||
i := int(math.Pow10(len - 1))
|
i := int(math.Pow10(len - 1))
|
||||||
ret := rand.Intn(m-i+1) + i
|
ret := rand.Intn(m-i+1) + i
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
@@ -362,9 +362,9 @@ func TestRandBoolSlice(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
func TestRandNumLen(t *testing.T) {
|
func TestRandNumberOfLength(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
randi := RandNumLen(6)
|
randi := RandNumberOfLength(6)
|
||||||
assert := internal.NewAssert(t, "TestRandNumLen")
|
assert := internal.NewAssert(t, "TestRandNumberOfLength")
|
||||||
assert.Equal(6, len(strconv.Itoa(randi)))
|
assert.Equal(6, len(strconv.Itoa(randi)))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user