diff --git a/docs/system.md b/docs/system.md new file mode 100644 index 0000000..6e2adae --- /dev/null +++ b/docs/system.md @@ -0,0 +1,242 @@ +# System +Package system contains some functions about os, runtime, shell command. + +
+ +## Source: + +[https://github.com/duke-git/lancet/blob/main/system/os.go](https://github.com/duke-git/lancet/blob/main/system/os.go) + + + + +## Usage: +```go +import ( + "github.com/duke-git/lancet/system" +) +``` + + + +## Index +- [IsWindows](#IsWindows) +- [IsLinux](#IsLinux) +- [IsMac](#IsMac) +- [GetOsEnv](#GetOsEnv) +- [SetOsEnv](#SetOsEnv) +- [RemoveOsEnv](#RemoveOsEnv) +- [CompareOsEnv](#CompareOsEnv) +- [ExecCommand](#ExecCommand) + + + + +## Documentation + + +### IsWindows +Check if current os is windows.
+ +Signature: + +```go +func IsWindows() bool +``` +Example: + +```go +import ( + "fmt" + "github.com/duke-git/lancet/system" +) + +func main() { + isOsWindows := system.IsWindows() + fmt.Println(isOsWindows) +} +``` + + + + +### IsLinux +Check if current os is linux.
+ +Signature: + +```go +func IsLinux() bool +``` +Example: + +```go +import ( + "fmt" + "github.com/duke-git/lancet/system" +) + +func main() { + isOsLinux := system.IsLinux() + fmt.Println(isOsLinux) +} +``` + + + +### IsMac +Check if current os is macos.
+ +Signature: + +```go +func IsMac() bool +``` +Example: + +```go +import ( + "fmt" + "github.com/duke-git/lancet/system" +) + +func main() { + isOsMac := system.IsMac + fmt.Println(isOsMac) +} +``` + + + +### GetOsEnv +Gets the value of the environment variable named by the key.
+ +Signature: + +```go +func GetOsEnv(key string) string +``` +Example: + +```go +import ( + "fmt" + "github.com/duke-git/lancet/system" +) + +func main() { + fooEnv := system.GetOsEnv("foo") + fmt.Println(fooEnv) +} +``` + + + +### SetOsEnv +Sets the value of the environment variable named by the key.
+ +Signature: + +```go +func SetOsEnv(key, value string) error +``` +Example: + +```go +import ( + "fmt" + "github.com/duke-git/lancet/system" +) + +func main() { + err := system.SetOsEnv("foo", "foo_value") + fmt.Println(err) +} +``` + + + + +### RemoveOsEnv +Remove a single environment variable.
+ +Signature: + +```go +func RemoveOsEnv(key string) error +``` +Example: + +```go +import ( + "fmt" + "github.com/duke-git/lancet/system" +) + +func main() { + err := system.RemoveOsEnv("foo") + if err != nil { + fmt.Println(err) + } +} +``` + + + +### CompareOsEnv +Get env named by the key and compare it with comparedEnv.
+ +Signature: + +```go +func CompareOsEnv(key, comparedEnv string) bool +``` +Example: + +```go +import ( + "fmt" + "github.com/duke-git/lancet/system" +) + +func main() { + system.SetOsEnv("foo", "foo_value") + res := system.CompareOsEnv("foo", "foo_value") + fmt.Println(res) //true +} +``` + + + + +### CompareOsEnv +use shell /bin/bash -c(linux) or cmd (windows) to execute command.
+ +Signature: + +```go +func ExecCommand(command string) (stdout, stderr string, err error) +``` +Example: + +```go +import ( + "fmt" + "github.com/duke-git/lancet/system" +) + +func main() { + out, errout, err := system.ExecCommand("ls") + fmt.Println(out) + fmt.Println(errout) + fmt.Println(err) +} +``` + + + + + + + + diff --git a/docs/system_zh-CN.md b/docs/system_zh-CN.md new file mode 100644 index 0000000..166d892 --- /dev/null +++ b/docs/system_zh-CN.md @@ -0,0 +1,242 @@ +# System +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) + + + + +## 用法: +```go +import ( + "github.com/duke-git/lancet/system" +) +``` + + + +## 目录 +- [IsWindows](#IsWindows) +- [IsLinux](#IsLinux) +- [IsMac](#IsMac) +- [GetOsEnv](#GetOsEnv) +- [SetOsEnv](#SetOsEnv) +- [RemoveOsEnv](#RemoveOsEnv) +- [CompareOsEnv](#CompareOsEnv) +- [ExecCommand](#ExecCommand) + + + + +## Documentation文档 + + +### IsWindows +检查当前操作系统是否是windows
+ +Signature: + +```go +func IsWindows() bool +``` +Example: + +```go +import ( + "fmt" + "github.com/duke-git/lancet/system" +) + +func main() { + isOsWindows := system.IsWindows() + fmt.Println(isOsWindows) +} +``` + + + + +### IsLinux +检查当前操作系统是否是linux
+ +Signature: + +```go +func IsLinux() bool +``` +Example: + +```go +import ( + "fmt" + "github.com/duke-git/lancet/system" +) + +func main() { + isOsLinux := system.IsLinux() + fmt.Println(isOsLinux) +} +``` + + + +### IsMac +检查当前操作系统是否是macos
+ +Signature: + +```go +func IsMac() bool +``` +Example: + +```go +import ( + "fmt" + "github.com/duke-git/lancet/system" +) + +func main() { + isOsMac := system.IsMac + fmt.Println(isOsMac) +} +``` + + + +### GetOsEnv +获取key命名的环境变量的值
+ +Signature: + +```go +func GetOsEnv(key string) string +``` +Example: + +```go +import ( + "fmt" + "github.com/duke-git/lancet/system" +) + +func main() { + fooEnv := system.GetOsEnv("foo") + fmt.Println(fooEnv) +} +``` + + + +### SetOsEnv +设置由key命名的环境变量的值
+ +Signature: + +```go +func SetOsEnv(key, value string) error +``` +Example: + +```go +import ( + "fmt" + "github.com/duke-git/lancet/system" +) + +func main() { + err := system.SetOsEnv("foo", "foo_value") + fmt.Println(err) +} +``` + + + + +### RemoveOsEnv +删除单个环境变量
+ +Signature: + +```go +func RemoveOsEnv(key string) error +``` +Example: + +```go +import ( + "fmt" + "github.com/duke-git/lancet/system" +) + +func main() { + err := system.RemoveOsEnv("foo") + if err != nil { + fmt.Println(err) + } +} +``` + + + +### CompareOsEnv +获取key命名的环境变量值并与compareEnv进行比较
+ +Signature: + +```go +func CompareOsEnv(key, comparedEnv string) bool +``` +Example: + +```go +import ( + "fmt" + "github.com/duke-git/lancet/system" +) + +func main() { + system.SetOsEnv("foo", "foo_value") + res := system.CompareOsEnv("foo", "foo_value") + fmt.Println(res) //true +} +``` + + + + +### CompareOsEnv +使用shell /bin/bash -c(linux) 或 cmd (windows) 执行shell命令
+ +Signature: + +```go +func ExecCommand(command string) (stdout, stderr string, err error) +``` +Example: + +```go +import ( + "fmt" + "github.com/duke-git/lancet/system" +) + +func main() { + out, errout, err := system.ExecCommand("ls") + fmt.Println(out) + fmt.Println(errout) + fmt.Println(err) +} +``` + + + + + + + +