github.com/sohaha/zlsgo@v1.7.13-0.20240501141223-10dd1a906f76/zutil/env.go (about) 1 package zutil 2 3 import ( 4 "os" 5 "runtime" 6 7 "github.com/sohaha/zlsgo/zfile" 8 ) 9 10 func GetOs() string { 11 return runtime.GOOS 12 } 13 14 // IsWin system. linux windows darwin 15 func IsWin() bool { 16 return GetOs() == "windows" 17 } 18 19 // IsMac system 20 func IsMac() bool { 21 return GetOs() == "darwin" 22 } 23 24 // IsLinux system 25 func IsLinux() bool { 26 return GetOs() == "linux" 27 } 28 29 // Getenv get ENV value by key name 30 func Getenv(name string, def ...string) string { 31 val := os.Getenv(name) 32 if val == "" && len(def) > 0 { 33 val = def[0] 34 } 35 return val 36 } 37 38 func GOROOT() string { 39 return zfile.RealPath(runtime.GOROOT()) 40 }