wslcheck

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 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 (
	ProcReleasePath = "/proc/sys/kernel/osrelease" // Path to `/proc` pseudo-file that shows release info
	VersionRegexp   = `.*microsoft-standard.*`     // Regular expression used to test against the output of ProcReleasePath
)

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.Printf("Am I running on WSL?\n")

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

Types

This section is empty.

Jump to

Keyboard shortcuts

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