osutil

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: Unlicense Imports: 3 Imported by: 0

Documentation

Overview

Package osutil contains utilities for functions requiring system calls and other OS-specific APIs. OS-specific network handling should go to github.com/AdguardTeam/golibs/netutil instead.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func RootDirFS

func RootDirFS() (fsys fs.FS)

RootDirFS returns a filesystem rooted at the system's root directory.

Example
package main

import (
	"fmt"

	"github.com/AdguardTeam/golibs/osutil"
)

func main() {
	fsys := osutil.RootDirFS()

	d, err := fsys.Open(".")
	if err != nil {
		fmt.Printf("opening: %v\n", err)

		return
	}

	fi, err := d.Stat()
	if err != nil {
		fmt.Printf("getting info: %v\n", err)

		return
	}

	fmt.Printf("is dir: %t\n", fi.IsDir())

	err = d.Close()
	if err != nil {
		fmt.Printf("closing: %v\n", err)

		return
	}

}
Output:

is dir: true

Types

type DefaultSignalNotifier

type DefaultSignalNotifier struct{}

DefaultSignalNotifier is a SignalNotifier that uses signal.Notify and signal.Stop.

func (DefaultSignalNotifier) Notify

func (n DefaultSignalNotifier) Notify(c chan<- os.Signal, sig ...os.Signal)

Notify implements the SignalNotifier interface for DefaultSignalNotifier.

func (DefaultSignalNotifier) Stop

func (n DefaultSignalNotifier) Stop(c chan<- os.Signal)

Stop implements the SignalNotifier interface for DefaultSignalNotifier.

type ExitCode

type ExitCode = int

ExitCode is a semantic alias for int when it's used as an exit code.

const (
	ExitCodeSuccess ExitCode = 0
	ExitCodeFailure ExitCode = 1
)

Exit status constants.

type SignalNotifier

type SignalNotifier interface {
	// Notify starts relaying incoming signals to c.  If no signals are
	// provided, all incoming signals are relayed to c.  Otherwise, just the
	// provided signals are.
	//
	// Implementations will not block sending to c: the caller must ensure that
	// c has sufficient buffer space to keep up with the expected signal rate.
	// For a channel used for notification of just one signal value, a buffer of
	// size 1 is sufficient.
	//
	// It is allowed to call Notify multiple times with the same channel: each
	// call expands the set of signals sent to that channel.  The only way to
	// remove signals from the set is to call Stop.
	//
	// It is allowed to call Notify multiple times with different channels and
	// the same signals: each channel receives copies of incoming signals
	// independently.
	//
	// See also [signal.Notify].
	Notify(c chan<- os.Signal, sig ...os.Signal)

	// Stop causes the SignalNotifier to stop relaying incoming signals to c.
	// It undoes the effect of all prior calls to Notify using c.  When Stop
	// returns, it c must not receive any more signals.
	//
	// See also [signal.Stop].
	Stop(c chan<- os.Signal)
}

SignalNotifier is the interface for OS functions that can notify about incoming signals using a channel.

Jump to

Keyboard shortcuts

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