Help us shape the future of Go! Take the 2026 Go Developer Survey

netmon

package
v0.37.2 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package netmon reports whether NetworkManager considers the machine online and the connection metered, and when either of those changes. Policy (skip, fetch, log) is the caller's: this package only reports.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Monitor

type Monitor struct {
	// contains filtered or unexported fields
}

Monitor reads NetworkManager's verdict on one system bus connection and reports its relevant changes. It is safe for concurrent use.

func Absent

func Absent() *Monitor

Absent returns a Monitor for a process with no system bus: Allowed always reports NMAbsent and Changed never fires.

func New

func New(sys *dbus.Conn, log *slog.Logger) *Monitor

New subscribes to NetworkManager's property changes on sys, a private system bus connection the caller keeps open and closes. NetworkManager need not be running: the match rule names its well-known name, which the bus resolves when a signal is sent, so a NetworkManager that starts later is heard. A failed subscription is logged at WARN and leaves Changed silent; Allowed still works. A nil log discards.

func (*Monitor) Allowed

func (m *Monitor) Allowed(ctx context.Context) (Verdict, error)

Allowed reads NetworkManager's Connectivity and Metered properties. Connectivity none, portal or limited is offline; unknown (checking disabled) and full are online. Metered yes or guess-yes is metered. NetworkManager not on the bus is a Verdict with NMAbsent, not an error.

func (*Monitor) Changed

func (m *Monitor) Changed() <-chan struct{}

Changed fires after NetworkManager reports a change to Connectivity or Metered. Changes that arrive before the receiver reads coalesce into one. The channel is never closed.

type Verdict

type Verdict struct {
	Online, Metered, NMAbsent bool
}

Verdict is what NetworkManager says about the network. When NMAbsent is true NetworkManager is not on the bus and Online and Metered carry no information.

Jump to

Keyboard shortcuts

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