The Barista Logo


An i3status alternative in golang

Download sample-bar Download i3status example View on GitHub


import ""

The netlink package provides a shared watcher for network link events. It allows clients to create filtered subscriptions for one or more links, and streams updates for each link to all interested clients.

There are several methods to create a subscription:

Call Unsubscribe when you’re no longer interested in updates. Because the order of updates is significant, the netlink watcher internally applies updates as soon as they’re received, and uses a notifier on C to signal changes.

At any point, the Get() will return the most appropriate link based on the subscription criteria.

sub := netlink.Any()
defer sub.Unsubscribe()

for range sub.C {
	link := sub.Get()
	// ...

There is also a MultiSubscription, returned by netlink.All(), that hooks into the global netlink listener directly. No unsubscribe call is necessary, since all MultiSubscriptions are a view on the same backing data that powers other netlink subscriptions.


Operational States

Links are prioritised based on their operational state. In decreasing priority, the operation states used by this package are:

IP Addresses

Within a link, the IP addresses are also sorted, so that .IPs[0] is the “best” IP address. IP addresses are prioritised as below: