option

package
v0.21.3 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2026 License: Apache-2.0 Imports: 4 Imported by: 40

Documentation

Index

Constants

View Source
const (
	DefaultChroot = "/"
)

Variables

View Source
var (
	NullAlerter = log.New(io.Discard, "", 0)
)

Functions

func EnvOrDefaultChroot

func EnvOrDefaultChroot() string

EnvOrDefaultChroot returns the value of the GHW_CHROOT environs variable or the default value of "/" if not set

func EnvOrDefaultDisableTools added in v0.21.3

func EnvOrDefaultDisableTools() bool

EnvOrDefaultDisableTools return true if ghw should use external tools to augment the data collected from sysfs. Most users want to do this most of time, so this is enabled by default. Users consuming snapshots may want to opt out, thus they can set the GHW_DISABLE_TOOLS environs variable to any value to make ghw skip calling external tools even if they are available.

Types

type Alerter

type Alerter interface {
	Printf(format string, v ...interface{})
}

Alerter emits warnings about undesirable but recoverable errors. We use a subset of a logger interface only to emit warnings, and `Warninger` sounded ugly.

func EnvOrDefaultAlerter

func EnvOrDefaultAlerter() Alerter

EnvOrDefaultAlerter returns the default instance ghw will use to emit its warnings. ghw will emit warnings to stderr by default unless the environs variable GHW_DISABLE_WARNINGS is specified; in the latter case all warning will be suppressed.

type Option

type Option func(opts *Options)

func WithAlerter

func WithAlerter(alerter Alerter) Option

WithAlerter sets alerting options for ghw

func WithChroot

func WithChroot(dir string) Option

WithChroot allows to override the root directory ghw uses.

func WithDisableTools

func WithDisableTools() Option

WithDisableTools revents ghw from calling external tools to discover hardware capabilities.

func WithNullAlerter

func WithNullAlerter() Option

WithNullAlerter sets No-op alerting options for ghw

func WithPCIDB added in v0.0.18

func WithPCIDB(pcidb *pcidb.PCIDB) Option

WithPCIDB allows you to provide a custom instance of the PCI database (pcidb.PCIDB) to ghw. This is useful if you want to use a preloaded or specially configured PCI database, such as one created with custom pcidb.WithOption settings, instead of letting ghw load the PCI database automatically.

func WithPathOverrides

func WithPathOverrides(overrides PathOverrides) Option

WithPathOverrides supplies path-specific overrides for the context

type Options added in v0.21.3

type Options struct {
	// To facilitate querying of sysfs filesystems that are bind-mounted to a
	// non-default root mountpoint, we allow users to set the GHW_CHROOT
	// environ variable to an alternate mountpoint. For instance, assume that
	// the user of ghw is a Golang binary being executed from an application
	// container that has certain host filesystems bind-mounted into the
	// container at /host. The user would ensure the GHW_CHROOT environ
	// variable is set to "/host" and ghw will build its paths from that
	// location instead of /
	Chroot string

	// Alerter contains the target for ghw warnings
	Alerter Alerter

	// DisableTools optionally request ghw to not call any external program to learn
	// about the hardware. The default is to use such tools if available.
	DisableTools bool

	// PathOverrides optionally allows to override the default paths ghw uses
	// internally to learn about the system resources.
	PathOverrides PathOverrides

	// PCIDB allows users to provide a custom instance of the PCI database
	// (pcidb.PCIDB) to be used by ghw. This can be useful for testing,
	// supplying a preloaded database, or providing an instance created with
	// custom pcidb.WithOption settings, instead of letting ghw load the PCI
	// database automatically.
	PCIDB *pcidb.PCIDB
}

Options is used to represent optionally-configured settings. Each field is a pointer to some concrete value so that we can tell when something has been set or left unset.

func FromEnv added in v0.21.3

func FromEnv() *Options

FromEnv returns an Options populated from the environs or default option values

func (*Options) Warn added in v0.21.3

func (o *Options) Warn(msg string, args ...interface{})

type PathOverrides

type PathOverrides map[string]string

PathOverrides is a map, keyed by the string name of a mount path, of override paths

Jump to

Keyboard shortcuts

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