| 67 | } |
| 68 | |
| 69 | func 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 | |
| 97 | func gracefulShutdown(etcdDataSource datasource.DataSource) { |
| 98 | err := etcdDataSource.Shutdown() |