Browse Source

InArray zu InSlice umbenannt

master
Klaus Wendel 2 years ago
parent
commit
8ed7a0c46b
  1. 10
      ebkTools.go

10
ebkTools.go

@ -12,6 +12,7 @@ package ebkTools
import (
"bytes"
"fmt"
"log"
"math"
"path"
"reflect"
@ -120,13 +121,18 @@ func Ip4or6(s string) uint8 {
return 0
}
// Find if value is contained by slice and return the position it was found
func InArray(array interface{}, value interface{}) (exists bool, index int) {
log.Println("InArray() is deprecated an should be replaced by InSlice()")
return InSlice(array, value)
}
func InSlice(slice interface{}, value interface{}) (exists bool, index int) {
exists = false
index = -1
switch reflect.TypeOf(array).Kind() {
switch reflect.TypeOf(slice).Kind() {
case reflect.Slice:
s := reflect.ValueOf(array)
s := reflect.ValueOf(slice)
for i := 0; i < s.Len(); i++ {
if reflect.DeepEqual(value, s.Index(i).Interface()) == true {

Loading…
Cancel
Save