func (chk InterfaceExists) Status() (int, string, error) { // getInterfaceNames returns the names of all network interfaces getInterfaceNames := func() (interfaces []string) { for _, iface := range netstatus.GetInterfaces() { interfaces = append(interfaces, iface.Name) } return } interfaces := getInterfaceNames() for _, iface := range interfaces { if iface == chk.name { return errutil.Success() } } return errutil.GenericError("Interface does not exist", chk.name, interfaces) }
func (chk Up) Status() (int, string, error) { // getUpInterfaces returns all the names of the interfaces that are up getUpInterfaces := func() (interfaceNames []string) { for _, iface := range netstatus.GetInterfaces() { if iface.Flags&net.FlagUp != 0 { interfaceNames = append(interfaceNames, iface.Name) } } return interfaceNames } upInterfaces := getUpInterfaces() if tabular.StrIn(chk.name, upInterfaces) { return errutil.Success() } return errutil.GenericError("Interface is not up", chk.name, upInterfaces) }