Files
2021-09-28 11:47:19 +08:00

52 lines
958 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package utils
import (
"fmt"
"reflect"
)
func InArray(search, needle interface{}) bool {
val := reflect.ValueOf(needle)
kind := val.Kind()
if kind == reflect.Slice || kind == reflect.Array {
for i := 0; i < val.Len(); i++ {
if val.Index(i).Interface() == search {
return true
}
}
}
return false
}
func ArrayFlip(src interface{}) interface{} {
val := reflect.ValueOf(src)
kind := val.Kind()
out := make(map[interface{}]interface{}, 0)
if kind == reflect.Slice || kind == reflect.Array || kind == reflect.Map {
for i := 0; i < val.Len(); i++ {
fmt.Printf("val.Field()%v\n", val.Index(i).MapKeys())
}
}
return out
}
func ArrayStrings(src interface{}) []string {
out := make([]string, 0)
val := reflect.ValueOf(src)
kind := val.Kind()
if kind == reflect.Slice || kind == reflect.Array {
for i := 0; i < val.Len(); i++ {
out = append(out, fmt.Sprintf("%v", val.Index(i).Interface()))
}
}
return out
}