1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-03-01 00:35:28 +08:00

doc: normalize document

This commit is contained in:
dudaodong
2023-01-14 12:48:39 +08:00
parent f976941e36
commit 6e3e411d46
7 changed files with 1042 additions and 917 deletions
+43 -13
View File
@@ -1,4 +1,5 @@
# Strutil
Package strutil contains some functions to manipulate string.
<div STYLE="page-break-after: always;"></div>
@@ -7,10 +8,10 @@ Package strutil contains some functions to manipulate string.
- [https://github.com/duke-git/lancet/blob/main/strutil/string.go](https://github.com/duke-git/lancet/blob/main/strutil/string.go)
<div STYLE="page-break-after: always;"></div>
## Usage:
```go
import (
"github.com/duke-git/lancet/v2/strutil"
@@ -20,6 +21,7 @@ import (
<div STYLE="page-break-after: always;"></div>
## Index
- [After](#After)
- [AfterLast](#AfterLast)
- [Before](#Before)
@@ -41,13 +43,12 @@ import (
- [Wrap](#Wrap)
- [Unwrap](#Unwrap)
<div STYLE="page-break-after: always;"></div>
## Documentation
### <span id="After">After</span>
<p>Returns the substring after the first occurrence of a specified string in the source string.</p>
<b>Signature:</b>
@@ -55,6 +56,7 @@ import (
```go
func After(s, char string) string
```
<b>Example:</b>
```go
@@ -86,6 +88,7 @@ func main() {
```
### <span id="AfterLast">AfterLast</span>
<p>Returns the substring after the last occurrence of a specified string in the source string.</p>
<b>Signature:</b>
@@ -93,6 +96,7 @@ func main() {
```go
func AfterLast(s, char string) string
```
<b>Example:</b>
```go
@@ -124,6 +128,7 @@ func main() {
```
### <span id="Before">Before</span>
<p>Returns the substring of the source string up to the first occurrence of the specified string.</p>
<b>Signature:</b>
@@ -131,6 +136,7 @@ func main() {
```go
func Before(s, char string) string
```
<b>Example:</b>
```go
@@ -159,6 +165,7 @@ func main() {
```
### <span id="BeforeLast">BeforeLast</span>
<p>Returns the substring of the source string up to the last occurrence of the specified string.</p>
<b>Signature:</b>
@@ -166,6 +173,7 @@ func main() {
```go
func BeforeLast(s, char string) string
```
<b>Example:</b>
```go
@@ -194,6 +202,7 @@ func main() {
```
### <span id="CamelCase">CamelCase</span>
<p>Coverts string to camelCase string, non letters and numbers will be ignored.</p>
<b>Signature:</b>
@@ -201,6 +210,7 @@ func main() {
```go
func CamelCase(s string) string
```
<b>Example:</b>
```go
@@ -227,6 +237,7 @@ func main() {
```
### <span id="KebabCase">KebabCase</span>
<p>KebabCase covert string to kebab-case, non letters and numbers will be ignored.</p>
<b>Signature:</b>
@@ -234,6 +245,7 @@ func main() {
```go
func KebabCase(s string) string
```
<b>Example:</b>
```go
@@ -260,6 +272,7 @@ func main() {
```
### <span id="UpperKebabCase">UpperKebabCase</span>
<p>UpperKebabCase covert string to upper KEBAB-CASE, non letters and numbers will be ignored.</p>
<b>Signature:</b>
@@ -267,6 +280,7 @@ func main() {
```go
func UpperKebabCase(s string) string
```
<b>Example:</b>
```go
@@ -293,6 +307,7 @@ func main() {
```
### <span id="Capitalize">Capitalize</span>
<p>Convert the first character of a string to upper case.</p>
<b>Signature:</b>
@@ -300,6 +315,7 @@ func main() {
```go
func Capitalize(s string) string
```
<b>Example:</b>
```go
@@ -326,6 +342,7 @@ func main() {
```
### <span id="IsString">IsString</span>
<p>Check if the value's data type is string.</p>
<b>Signature:</b>
@@ -333,6 +350,7 @@ func main() {
```go
func IsString(v any) bool
```
<b>Example:</b>
```go
@@ -364,6 +382,7 @@ func main() {
```
### <span id="LowerFirst">LowerFirst</span>
<p>Convert the first character of string to lower case.</p>
<b>Signature:</b>
@@ -371,6 +390,7 @@ func main() {
```go
func LowerFirst(s string) string
```
<b>Example:</b>
```go
@@ -396,6 +416,7 @@ func main() {
```
### <span id="UpperFirst">UpperFirst</span>
<p>Convert the first character of string to upper case.</p>
<b>Signature:</b>
@@ -403,6 +424,7 @@ func main() {
```go
func UpperFirst(s string) string
```
<b>Example:</b>
```go
@@ -428,6 +450,7 @@ func main() {
```
### <span id="PadEnd">PadEnd</span>
<p>Pads string on the right side if it's shorter than size.</p>
<b>Signature:</b>
@@ -435,6 +458,7 @@ func main() {
```go
func PadEnd(source string, size int, padStr string) string
```
<b>Example:</b>
```go
@@ -472,6 +496,7 @@ func main() {
```
### <span id="PadStart">PadStart</span>
<p>Pads string on the left side if it's shorter than size.</p>
<b>Signature:</b>
@@ -479,6 +504,7 @@ func main() {
```go
func PadStart(source string, size int, padStr string) string
```
<b>Example:</b>
```go
@@ -516,6 +542,7 @@ func main() {
```
### <span id="Reverse">Reverse</span>
<p>Return string whose char order is reversed to the given string.</p>
<b>Signature:</b>
@@ -523,6 +550,7 @@ func main() {
```go
func Reverse(s string) string
```
<b>Example:</b>
```go
@@ -545,6 +573,7 @@ func main() {
```
### <span id="SnakeCase">SnakeCase</span>
<p>Coverts string to snake_case, non letters and numbers will be ignored.</p>
<b>Signature:</b>
@@ -552,6 +581,7 @@ func main() {
```go
func SnakeCase(s string) string
```
<b>Example:</b>
```go
@@ -578,6 +608,7 @@ func main() {
```
### <span id="UpperSnakeCase">UpperSnakeCase</span>
<p>Coverts string to upper KEBAB-CASE, non letters and numbers will be ignored.</p>
<b>Signature:</b>
@@ -585,6 +616,7 @@ func main() {
```go
func SnakeCase(s string) string
```
<b>Example:</b>
```go
@@ -611,6 +643,7 @@ func main() {
```
### <span id="SplitEx">SplitEx</span>
<p>Split a given string whether the result contains empty string.</p>
<b>Signature:</b>
@@ -618,6 +651,7 @@ func main() {
```go
func SplitEx(s, sep string, removeEmptyString bool) []string
```
<b>Example:</b>
```go
@@ -650,6 +684,7 @@ func main() {
```
### <span id="Substring">Substring</span>
<p>Returns a substring of the specified length starting at the specified offset position.</p>
<b>Signature:</b>
@@ -657,6 +692,7 @@ func main() {
```go
func Substring(s string, offset int, length uint) string
```
<b>Example:</b>
```go
@@ -691,6 +727,7 @@ func main() {
```
### <span id="Wrap">Wrap</span>
<p>Wrap a string with given string.</p>
<b>Signature:</b>
@@ -698,6 +735,7 @@ func main() {
```go
func Wrap(str string, wrapWith string) string
```
<b>Example:</b>
```go
@@ -725,8 +763,8 @@ func main() {
}
```
### <span id="Wrap">Wrap</span>
<p>Unwrap a given string from anther string. will change source string.</p>
<b>Signature:</b>
@@ -734,6 +772,7 @@ func main() {
```go
func Unwrap(str string, wrapToken string) string
```
<b>Example:</b>
```go
@@ -763,12 +802,3 @@ func main() {
// *foo*
}
```
+45 -7
View File
@@ -1,5 +1,6 @@
# Strutil
strutil包含处理字符串的相关函数。
strutil 包含处理字符串的相关函数。
<div STYLE="page-break-after: always;"></div>
@@ -7,10 +8,10 @@ strutil包含处理字符串的相关函数。
- [https://github.com/duke-git/lancet/blob/main/strutil/string.go](https://github.com/duke-git/lancet/blob/main/strutil/string.go)
<div STYLE="page-break-after: always;"></div>
## 用法:
```go
import (
"github.com/duke-git/lancet/v2/strutil"
@@ -20,6 +21,7 @@ import (
<div STYLE="page-break-after: always;"></div>
## 目录
- [After](#After)
- [AfterLast](#AfterLast)
- [Before](#Before)
@@ -41,14 +43,12 @@ import (
- [Wrap](#Wrap)
- [Unwrap](#Unwrap)
<div STYLE="page-break-after: always;"></div>
## Documentation文档
## Documentation 文档
### <span id="After">After</span>
<p>返回源字符串中特定字符串首次出现时的位置之后的子字符串。</p>
<b>函数签名:</b>
@@ -56,6 +56,7 @@ import (
```go
func After(s, char string) string
```
<b>示例:</b>
```go
@@ -87,6 +88,7 @@ func main() {
```
### <span id="AfterLast">AfterLast</span>
<p>返回源字符串中指定字符串最后一次出现时的位置之后的子字符串。</p>
<b>函数签名:</b>
@@ -94,6 +96,7 @@ func main() {
```go
func AfterLast(s, char string) string
```
<b>示例:</b>
```go
@@ -125,6 +128,7 @@ func main() {
```
### <span id="Before">Before</span>
<p>返回源字符串中指定字符串第一次出现时的位置之前的子字符串。</p>
<b>函数签名:</b>
@@ -132,6 +136,7 @@ func main() {
```go
func Before(s, char string) string
```
<b>示例:</b>
```go
@@ -160,6 +165,7 @@ func main() {
```
### <span id="BeforeLast">BeforeLast</span>
<p>返回源字符串中指定字符串最后一次出现时的位置之前的子字符串。</p>
<b>函数签名:</b>
@@ -167,6 +173,7 @@ func main() {
```go
func BeforeLast(s, char string) string
```
<b>示例:</b>
```go
@@ -195,6 +202,7 @@ func main() {
```
### <span id="CamelCase">CamelCase</span>
<p>将字符串转换为驼峰式字符串, 非字母和数字会被忽略。</p>
<b>函数签名:</b>
@@ -202,6 +210,7 @@ func main() {
```go
func CamelCase(s string) string
```
<b>示例:</b>
```go
@@ -228,6 +237,7 @@ func main() {
```
### <span id="KebabCase">KebabCase</span>
<p>将字符串转换为kebab-case, 非字母和数字会被忽略。</p>
<b>函数签名:</b>
@@ -235,6 +245,7 @@ func main() {
```go
func KebabCase(s string) string
```
<b>示例:</b>
```go
@@ -261,6 +272,7 @@ func main() {
```
### <span id="UpperKebabCase">UpperKebabCase</span>
<p>将字符串转换为大写KEBAB-CASE, 非字母和数字会被忽略。</p>
<b>函数签名:</b>
@@ -268,6 +280,7 @@ func main() {
```go
func UpperKebabCase(s string) string
```
<b>示例:</b>
```go
@@ -294,6 +307,7 @@ func main() {
```
### <span id="Capitalize">Capitalize</span>
<p>将字符串的第一个字符转换为大写。</p>
<b>函数签名:</b>
@@ -301,6 +315,7 @@ func main() {
```go
func Capitalize(s string) string
```
<b>示例:</b>
```go
@@ -327,6 +342,7 @@ func main() {
```
### <span id="IsString">IsString</span>
<p>判断传入参数的数据类型是否为字符串。</p>
<b>函数签名:</b>
@@ -334,6 +350,7 @@ func main() {
```go
func IsString(v any) bool
```
<b>示例:</b>
```go
@@ -365,6 +382,7 @@ func main() {
```
### <span id="LowerFirst">LowerFirst</span>
<p>将字符串的第一个字符转换为小写。</p>
<b>函数签名:</b>
@@ -372,6 +390,7 @@ func main() {
```go
func LowerFirst(s string) string
```
<b>示例:</b>
```go
@@ -397,6 +416,7 @@ func main() {
```
### <span id="UpperFirst">UpperFirst</span>
<p>将字符串的第一个字符转换为大写形式。</p>
<b>函数签名:</b>
@@ -404,6 +424,7 @@ func main() {
```go
func UpperFirst(s string) string
```
<b>示例:</b>
```go
@@ -429,6 +450,7 @@ func main() {
```
### <span id="PadEnd">PadEnd</span>
<p>如果字符串长度短于size,则在右侧填充字符串。</p>
<b>函数签名:</b>
@@ -436,6 +458,7 @@ func main() {
```go
func PadEnd(source string, size int, padStr string) string
```
<b>示例:</b>
```go
@@ -473,6 +496,7 @@ func main() {
```
### <span id="PadStart">PadStart</span>
<p>如果字符串长度短于size,则在左侧填充字符串。</p>
<b>函数签名:</b>
@@ -480,6 +504,7 @@ func main() {
```go
func PadStart(source string, size int, padStr string) string
```
<b>示例:</b>
```go
@@ -517,6 +542,7 @@ func main() {
```
### <span id="Reverse">Reverse</span>
<p>返回字符顺序与给定字符串相反的字符串。</p>
<b>函数签名:</b>
@@ -524,6 +550,7 @@ func main() {
```go
func Reverse(s string) string
```
<b>示例:</b>
```go
@@ -546,6 +573,7 @@ func main() {
```
### <span id="SnakeCase">SnakeCase</span>
<p>将字符串转换为snake_case形式, 非字母和数字会被忽略。</p>
<b>函数签名:</b>
@@ -553,6 +581,7 @@ func main() {
```go
func SnakeCase(s string) string
```
<b>示例:</b>
```go
@@ -579,6 +608,7 @@ func main() {
```
### <span id="UpperSnakeCase">UpperSnakeCase</span>
<p>将字符串转换为大写SNAKE_CASE形式, 非字母和数字会被忽略。</p>
<b>函数签名:</b>
@@ -586,6 +616,7 @@ func main() {
```go
func SnakeCase(s string) string
```
<b>示例:</b>
```go
@@ -612,6 +643,7 @@ func main() {
```
### <span id="SplitEx">SplitEx</span>
<p>分割字符串为切片,removeEmptyString参数指定是否去除空字符串。</p>
<b>函数签名:</b>
@@ -619,6 +651,7 @@ func main() {
```go
func SplitEx(s, sep string, removeEmptyString bool) []string
```
<b>示例:</b>
```go
@@ -651,6 +684,7 @@ func main() {
```
### <span id="Substring">Substring</span>
<p>根据指定的位置和长度截取字符串。</p>
<b>函数签名:</b>
@@ -658,6 +692,7 @@ func main() {
```go
func Substring(s string, offset int, length uint) string
```
<b>示例:</b>
```go
@@ -692,6 +727,7 @@ func main() {
```
### <span id="Wrap">Wrap</span>
<p>用另一个字符串包裹一个字符串。</p>
<b>函数签名:</b>
@@ -699,6 +735,7 @@ func main() {
```go
func Wrap(str string, wrapWith string) string
```
<b>示例:</b>
```go
@@ -726,8 +763,8 @@ func main() {
}
```
### <span id="Wrap">Wrap</span>
<p>用另一个字符串解开包裹一个字符串。</p>
<b>函数签名:</b>
@@ -735,6 +772,7 @@ func main() {
```go
func Unwrap(str string, wrapToken string) string
```
<b>示例:</b>
```go
+64 -37
View File
@@ -1,4 +1,5 @@
# System
Package system contains some functions about os, runtime, shell command.
<div STYLE="page-break-after: always;"></div>
@@ -7,10 +8,10 @@ Package system contains some functions about os, runtime, shell command.
- [https://github.com/duke-git/lancet/blob/main/system/os.go](https://github.com/duke-git/lancet/blob/main/system/os.go)
<div STYLE="page-break-after: always;"></div>
## Usage:
```go
import (
"github.com/duke-git/lancet/v2/system"
@@ -20,6 +21,7 @@ import (
<div STYLE="page-break-after: always;"></div>
## Index
- [IsWindows](#IsWindows)
- [IsLinux](#IsLinux)
- [IsMac](#IsMac)
@@ -30,13 +32,12 @@ import (
- [ExecCommand](#ExecCommand)
- [GetOsBits](#GetOsBits)
<div STYLE="page-break-after: always;"></div>
## Documentation
### <span id="IsWindows">IsWindows</span>
<p>Check if current os is windows.</p>
<b>Signature:</b>
@@ -44,6 +45,7 @@ import (
```go
func IsWindows() bool
```
<b>Example:</b>
```go
@@ -58,10 +60,8 @@ func main() {
}
```
### <span id="IsLinux">IsLinux</span>
<p>Check if current os is linux.</p>
<b>Signature:</b>
@@ -69,6 +69,7 @@ func main() {
```go
func IsLinux() bool
```
<b>Example:</b>
```go
@@ -83,9 +84,8 @@ func main() {
}
```
### <span id="IsMac">IsMac</span>
<p>Check if current os is macos.</p>
<b>Signature:</b>
@@ -93,6 +93,7 @@ func main() {
```go
func IsMac() bool
```
<b>Example:</b>
```go
@@ -107,9 +108,8 @@ func main() {
}
```
### <span id="GetOsEnv">GetOsEnv</span>
<p>Gets the value of the environment variable named by the key.</p>
<b>Signature:</b>
@@ -117,6 +117,7 @@ func main() {
```go
func GetOsEnv(key string) string
```
<b>Example:</b>
```go
@@ -126,14 +127,19 @@ import (
)
func main() {
fooEnv := system.GetOsEnv("foo")
fmt.Println(fooEnv)
err := system.SetOsEnv("foo", "abc")
result := system.GetOsEnv("foo")
fmt.Println(err)
fmt.Println(result)
// Output:
// <nil>
// abc
}
```
### <span id="SetOsEnv">SetOsEnv</span>
<p>Sets the value of the environment variable named by the key.</p>
<b>Signature:</b>
@@ -141,6 +147,7 @@ func main() {
```go
func SetOsEnv(key, value string) error
```
<b>Example:</b>
```go
@@ -150,15 +157,19 @@ import (
)
func main() {
err := system.SetOsEnv("foo", "foo_value")
err := system.SetOsEnv("foo", "abc")
result := system.GetOsEnv("foo")
fmt.Println(err)
fmt.Println(result)
// Output:
// <nil>
// abc
}
```
### <span id="RemoveOsEnv">RemoveOsEnv</span>
<p>Remove a single environment variable.</p>
<b>Signature:</b>
@@ -166,6 +177,7 @@ func main() {
```go
func RemoveOsEnv(key string) error
```
<b>Example:</b>
```go
@@ -175,16 +187,27 @@ import (
)
func main() {
err := system.RemoveOsEnv("foo")
if err != nil {
fmt.Println(err)
}
err1 := system.SetOsEnv("foo", "abc")
result1 := GetOsEnv("foo")
err2 := system.RemoveOsEnv("foo")
result2 := GetOsEnv("foo")
fmt.Println(err1)
fmt.Println(err2)
fmt.Println(result1)
fmt.Println(result2)
// Output:
// <nil>
// <nil>
// abc
//
}
```
### <span id="CompareOsEnv">CompareOsEnv</span>
<p>Get env named by the key and compare it with comparedEnv.</p>
<b>Signature:</b>
@@ -192,6 +215,7 @@ func main() {
```go
func CompareOsEnv(key, comparedEnv string) bool
```
<b>Example:</b>
```go
@@ -201,16 +225,22 @@ import (
)
func main() {
system.SetOsEnv("foo", "foo_value")
res := system.CompareOsEnv("foo", "foo_value")
fmt.Println(res) //true
err := system.SetOsEnv("foo", "abc")
if err != nil {
return
}
result := system.CompareOsEnv("foo", "abc")
fmt.Println(result)
// Output:
// true
}
```
### <span id="ExecCommand">CompareOsEnv</span>
<p>Execute shell command, return the stdout and stderr string of command, and error if error occur. param `command` is a complete command string, like, ls -a (linux), dir(windows), ping 127.0.0.1. In linux, use /bin/bash -c to execute command, In windows, use powershell.exe to execute command.</p>
<b>Signature:</b>
@@ -218,6 +248,7 @@ func main() {
```go
func ExecCommand(command string) (stdout, stderr string, err error)
```
<b>Example:</b>
```go
@@ -248,10 +279,8 @@ func main() {
}
```
### <span id="GetOsBits">GetOsBits</span>
<p>Get current os bits, 32bit or 64bit. return 32 or 64</p>
<b>Signature:</b>
@@ -259,6 +288,7 @@ func main() {
```go
func GetOsBits() int
```
<b>Example:</b>
```go
@@ -269,9 +299,6 @@ import (
func main() {
osBit := system.GetOsBits()
fmt.Println(osBit)
fmt.Println(osBit) // 32 or 64
}
```
+66 -43
View File
@@ -1,5 +1,6 @@
# System
system包含os, runtime, shell command相关函数。
system 包含 os, runtime, shell command 相关函数。
<div STYLE="page-break-after: always;"></div>
@@ -7,10 +8,10 @@ system包含os, runtime, shell command相关函数。
- [https://github.com/duke-git/lancet/blob/main/system/os.go](https://github.com/duke-git/lancet/blob/main/system/os.go)
<div STYLE="page-break-after: always;"></div>
## 用法:
```go
import (
"github.com/duke-git/lancet/v2/system"
@@ -20,6 +21,7 @@ import (
<div STYLE="page-break-after: always;"></div>
## 目录
- [IsWindows](#IsWindows)
- [IsLinux](#IsLinux)
- [IsMac](#IsMac)
@@ -30,13 +32,12 @@ import (
- [ExecCommand](#ExecCommand)
- [GetOsBits](#GetOsBits)
<div STYLE="page-break-after: always;"></div>
## Documentation文档
## Documentation 文档
### <span id="IsWindows">IsWindows</span>
<p>检查当前操作系统是否是windows</p>
<b>Signature:</b>
@@ -44,6 +45,7 @@ import (
```go
func IsWindows() bool
```
<b>Example:</b>
```go
@@ -58,10 +60,8 @@ func main() {
}
```
### <span id="IsLinux">IsLinux</span>
<p>检查当前操作系统是否是linux</p>
<b>Signature:</b>
@@ -69,6 +69,7 @@ func main() {
```go
func IsLinux() bool
```
<b>Example:</b>
```go
@@ -83,9 +84,8 @@ func main() {
}
```
### <span id="IsMac">IsMac</span>
<p>检查当前操作系统是否是macos</p>
<b>Signature:</b>
@@ -93,6 +93,7 @@ func main() {
```go
func IsMac() bool
```
<b>Example:</b>
```go
@@ -107,9 +108,8 @@ func main() {
}
```
### <span id="GetOsEnv">GetOsEnv</span>
<p>获取key命名的环境变量的值</p>
<b>Signature:</b>
@@ -117,6 +117,7 @@ func main() {
```go
func GetOsEnv(key string) string
```
<b>Example:</b>
```go
@@ -126,14 +127,19 @@ import (
)
func main() {
fooEnv := system.GetOsEnv("foo")
fmt.Println(fooEnv)
err := system.SetOsEnv("foo", "abc")
result := system.GetOsEnv("foo")
fmt.Println(err)
fmt.Println(result)
// Output:
// <nil>
// abc
}
```
### <span id="SetOsEnv">SetOsEnv</span>
<p>设置由key命名的环境变量的值</p>
<b>Signature:</b>
@@ -141,6 +147,7 @@ func main() {
```go
func SetOsEnv(key, value string) error
```
<b>Example:</b>
```go
@@ -150,15 +157,19 @@ import (
)
func main() {
err := system.SetOsEnv("foo", "foo_value")
err := system.SetOsEnv("foo", "abc")
result := system.GetOsEnv("foo")
fmt.Println(err)
fmt.Println(result)
// Output:
// <nil>
// abc
}
```
### <span id="RemoveOsEnv">RemoveOsEnv</span>
<p>删除单个环境变量</p>
<b>Signature:</b>
@@ -166,6 +177,7 @@ func main() {
```go
func RemoveOsEnv(key string) error
```
<b>Example:</b>
```go
@@ -175,16 +187,27 @@ import (
)
func main() {
err := system.RemoveOsEnv("foo")
if err != nil {
fmt.Println(err)
}
err1 := system.SetOsEnv("foo", "abc")
result1 := GetOsEnv("foo")
err2 := system.RemoveOsEnv("foo")
result2 := GetOsEnv("foo")
fmt.Println(err1)
fmt.Println(err2)
fmt.Println(result1)
fmt.Println(result2)
// Output:
// <nil>
// <nil>
// abc
//
}
```
### <span id="CompareOsEnv">CompareOsEnv</span>
<p>获取key命名的环境变量值并与compareEnv进行比较</p>
<b>Signature:</b>
@@ -192,6 +215,7 @@ func main() {
```go
func CompareOsEnv(key, comparedEnv string) bool
```
<b>Example:</b>
```go
@@ -201,16 +225,22 @@ import (
)
func main() {
system.SetOsEnv("foo", "foo_value")
res := system.CompareOsEnv("foo", "foo_value")
fmt.Println(res) //true
err := system.SetOsEnv("foo", "abc")
if err != nil {
return
}
result := system.CompareOsEnv("foo", "abc")
fmt.Println(result)
// Output:
// true
}
```
### <span id="ExecCommand">ExecCommand</span>
<p>执行shell命令,返回命令的stdout和stderr字符串,如果出现错误,则返回错误。参数`command`是一个完整的命令字符串,如ls-alinux),dirwindows),ping 127.0.0.1。在linux中,使用/bin/bash-c执行命令,在windows中,使用powershell.exe执行命令。</p>
<b>Signature:</b>
@@ -218,6 +248,7 @@ func main() {
```go
func ExecCommand(command string) (stdout, stderr string, err error)
```
<b>Example:</b>
```go
@@ -248,10 +279,8 @@ func main() {
}
```
### <span id="GetOsBits">GetOsBits</span>
<p>获取当前操作系统位数,返回32或64</p>
<b>函数签名:</b>
@@ -259,6 +288,7 @@ func main() {
```go
func GetOsBits() int
```
<b>例子:</b>
```go
@@ -269,13 +299,6 @@ import (
func main() {
osBit := system.GetOsBits()
fmt.Println(osBit)
fmt.Println(osBit) // 32 or 64
}
```
+5 -2
View File
@@ -1,4 +1,5 @@
# Xerror
Package xerror implements helpers for errors.
<div STYLE="page-break-after: always;"></div>
@@ -10,6 +11,7 @@ Package xerror implements helpers for errors.
<div STYLE="page-break-after: always;"></div>
## Usage:
```go
import (
"github.com/duke-git/lancet/v2/xerror"
@@ -19,15 +21,15 @@ import (
<div STYLE="page-break-after: always;"></div>
## Index
- [Unwrap](#Unwrap)
<div STYLE="page-break-after: always;"></div>
## Documentation
### <span id="Unwrap">Unwrap</span>
<p>Unwrap if err is nil then it returns a valid value. If err is not nil, Unwrap panics with err.</p>
<b>Signature:</b>
@@ -35,6 +37,7 @@ import (
```go
func Unwrap[T any](val T, err error) T
```
<b>Example:</b>
```go
+6 -3
View File
@@ -1,5 +1,6 @@
# Xerror
xerror错误处理逻辑封装
xerror 错误处理逻辑封装
<div STYLE="page-break-after: always;"></div>
@@ -10,6 +11,7 @@ xerror错误处理逻辑封装
<div STYLE="page-break-after: always;"></div>
## 用法:
```go
import (
"github.com/duke-git/lancet/v2/xerror"
@@ -19,15 +21,15 @@ import (
<div STYLE="page-break-after: always;"></div>
## 目录
- [Unwrap](#Unwrap)
<div STYLE="page-break-after: always;"></div>
## 文档
### <span id="Unwrap">Unwrap</span>
<p>检查error, 如果err为nil则展开,则它返回一个有效值,如果err不是nil则Unwrap使用err发生panic。</p>
<b>函数签名:</b>
@@ -35,6 +37,7 @@ import (
```go
func Unwrap[T any](val T, err error) T
```
<b>例子:</b>
```go
+9 -8
View File
@@ -3,10 +3,10 @@ package system
import "fmt"
func ExampleSetOsEnv() {
ok := SetOsEnv("foo", "abc")
err := SetOsEnv("foo", "abc")
result := GetOsEnv("foo")
fmt.Println(ok)
fmt.Println(err)
fmt.Println(result)
// Output:
// <nil>
@@ -25,14 +25,14 @@ func ExampleGetOsEnv() {
}
func ExampleRemoveOsEnv() {
ok1 := SetOsEnv("foo", "abc")
err1 := SetOsEnv("foo", "abc")
result1 := GetOsEnv("foo")
ok2 := RemoveOsEnv("foo")
err2 := RemoveOsEnv("foo")
result2 := GetOsEnv("foo")
fmt.Println(ok1)
fmt.Println(ok2)
fmt.Println(err1)
fmt.Println(err2)
fmt.Println(result1)
fmt.Println(result2)
@@ -49,9 +49,10 @@ func ExampleCompareOsEnv() {
return
}
result1 := CompareOsEnv("foo", "abc")
result := CompareOsEnv("foo", "abc")
fmt.Println(result)
fmt.Println(result1)
// Output:
// true
}