Files
steampipe/utils/wsl.go
Eng Zer Jun 335a3ee686 refactor: move from io/ioutil to io and os packages (#1153)
The io/ioutil package has been deprecated as of Go 1.16, see
https://golang.org/doc/go1.16#ioutil. This commit replaces the existing
io/ioutil functions with their new definitions in io and os packages.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2021-11-23 11:54:38 +00:00

23 lines
598 B
Go

package utils
import (
"os"
"runtime"
"strings"
)
// IsWSL :: detects whether app is running in WSL environment
// refer to: https://github.com/Microsoft/WSL/issues/423#issuecomment-679190758
func IsWSL() (bool, error) {
if runtime.GOOS != "linux" {
return false, nil
}
// https://github.com/Microsoft/WSL/issues/2299#issuecomment-361366982
osReleaseContent, err := os.ReadFile("/proc/version")
if err != nil {
return false, err
}
osRelease := strings.ToLower(string(osReleaseContent))
return (strings.Contains(osRelease, "microsoft") || strings.Contains(osRelease, "wsl")), nil
}