sysctl

package module
v0.0.0-...-601aec5 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2025 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(key string) (string, error)

Get returns the value of key as string.

Example

Get will return the OS release version. On linux the kernel version something like: 6.13.3 On OpenBSD something like: 7.6

package main

import (
	"fmt"
	"runtime"

	"catinello.eu/sysctl"
)

func main() {
	var key string

	switch runtime.GOOS {
	case "linux":
		key = "kernel.osrelease"
	case "openbsd", "freebsd", "netbsd", "dragonfly", "darwin":
		key = "kern.osrelease"
	}

	version, err := sysctl.Get(key)
	if err != nil {
		panic(err)
	}

	fmt.Println(version)
}
Output:

func List

func List() ([]string, error)

List returns a slice of strings of all available keys.

Example

List will return a list of available sysctl keys. We will filter by "kern" prefix.

package main

import (
	"fmt"
	"strings"

	"catinello.eu/sysctl"
)

func main() {
	list, err := sysctl.List()
	if err != nil {
		panic(err)
	}

	for _, l := range list {
		if strings.HasPrefix(l, "kern") {
			fmt.Println(l)
		}
	}
}
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳