wslcheck

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2021 License: ISC Imports: 3 Imported by: 0

README

wslcheck GoDoc

Go module to check whether your program is running on Windows Subsystem for Linux.

This module works by checking the contents of /proc/sys/kernel/osrelease.

Usage

$ go get github.com/e-zk/wslcheck
package main

import (
	"fmt"
	"github.com/e-zk/wslcheck"
)

func main() {
	fmt.Printf("Am I running on WSL?\n")

	wsl, _ := wslcheck.Check()
	if wsl == true {
		fmt.Printf("Yes!\n")
	} else {
		fmt.Printf("No!\n")
	}
}

Documentation

Overview

The wslcheck package provides a simple function that checks whether the current Linux environment is in fact the Windows Subsystem for Linux (WSL).

Index

Examples

Constants

View Source
const (
	// Path to `/proc` pseudo-file that shows release info
	ProcReleasePath = "/proc/sys/kernel/osrelease"
	// Regular expression used to test against the output of ProcReleasePath
	VersionRegexp = `.*microsoft-standard.*|.*Microsoft.*`
)

Variables

This section is empty.

Functions

func Check

func Check() (bool, error)

Check returns true if the Linux version string matches that of a WSL distribution. Otherwise (including when the host OS is not Linux at all), it returns false.

If an error occurs when attempting to get the version string, Check will return false and the error value will be populated (not-nil).

Example

The simplest possible use of this function

package main

import (
	"fmt"
	"github.com/e-zk/wslcheck"
)

func main() {
	fmt.Println("Am I running on WSL?")

	wsl, _ := wslcheck.Check()
	if wsl == true {
		fmt.Println("Yes!")
	} else {
		fmt.Println("No!")
	}
}
Output:

func CheckVer added in v1.0.1

func CheckVer(verBytes []byte) bool

Check the given version string (as a byte slice) matches that of a WSL distribution. Returns true if the version string matches. Otherwise it returns false.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL