network

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package network reports whether the machine is online, over what kind of link, whether the connection is metered, and when that changes.

st, err := network.Get(a)
if st.Online && !st.Metered { startBigDownload() }
network.OnChange(a, func(st network.Status) { banner.SetVisible(!st.Online) })

Platforms: macOS uses Network.framework's path monitor (nw_path_monitor); Windows the Network List Manager (INetworkListManager connectivity and connection cost) with IP interface change notifications; Linux NetworkManager over the system D-Bus; iOS the same path monitor as macOS; Android ConnectivityManager's default-network callback (Online needs a validated internet connection, Constrained is Data Saver on a metered network; the host manifest declares ACCESS_NETWORK_STATE). "Online" is the system's own judgement (a usable default route, or NetworkManager's connectivity check), not a probe of any particular server.

Functions are safe from any goroutine once the app runs; handlers run on the main thread and only for real changes. OnChange may be called before Run. Get returns ErrUnsupported where the backend cannot tell (minimal backends, Linux without NetworkManager) and tango.ErrNotRunning after the app quit.

Index

Constants

Variables

View Source
var ErrUnsupported = platform.ErrUnsupported

ErrUnsupported is platform.ErrUnsupported.

Functions

func KindString

func KindString(k Kind) string

KindString names k ("wired", "wifi", "cellular", "none", "other", "unknown"), for logs and the JS API.

func OnChange

func OnChange(a *tango.App, fn func(Status))

OnChange calls fn whenever connectivity, the link kind or the metered flags change.

Types

type Kind

type Kind = platform.NetworkKind

Kind is the type of link the default route uses.

type Status

type Status = platform.NetworkStatus

Status is a snapshot of connectivity.

func Get

func Get(a *tango.App) (Status, error)

Get returns the current connectivity.

Jump to

Keyboard shortcuts

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