MCPcopy Create free account
hub / github.com/cafebazaar/blacksmith / interfaceIP

Function interfaceIP

blacksmith.go:69–95  ·  view source on GitHub ↗
(iface *net.Interface)

Source from the content-addressed store, hash-verified

67}
68
69func interfaceIP(iface *net.Interface) (net.IP, error) {
70 addrs, err := iface.Addrs()
71 if err != nil {
72 return nil, err
73 }
74 fs := [](func(net.IP) bool){
75 net.IP.IsGlobalUnicast,
76 net.IP.IsLinkLocalUnicast,
77 net.IP.IsLoopback,
78 }
79 for _, f := range fs {
80 for _, a := range addrs {
81 ipaddr, ok := a.(*net.IPNet)
82 if !ok {
83 continue
84 }
85 ip := ipaddr.IP.To4()
86 if ip == nil {
87 continue
88 }
89 if f(ip) {
90 return ip, nil
91 }
92 }
93 }
94 return nil, fmt.Errorf("interface %s has no usable unicast addresses", iface.Name)
95}
96
97func gracefulShutdown(etcdDataSource datasource.DataSource) {
98 err := etcdDataSource.Shutdown()

Callers 1

mainFunction · 0.85

Calls 1

fFunction · 0.85

Tested by

no test coverage detected