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 ¶
const ( Unknown = platform.NetworkUnknown None = platform.NetworkNone Wired = platform.NetworkWired WiFi = platform.NetworkWiFi Cellular = platform.NetworkCellular Other = platform.NetworkOther )
Variables ¶
var ErrUnsupported = platform.ErrUnsupported
ErrUnsupported is platform.ErrUnsupported.
Functions ¶
func KindString ¶
KindString names k ("wired", "wifi", "cellular", "none", "other", "unknown"), for logs and the JS API.