dashboard/utils/sliceutils.go
2019-05-26 02:47:51 +01:00

35 lines
825 B
Go

package utils
import (
"github.com/TicketsBot/GoPanel/utils/discord/objects"
"reflect"
)
func Contains(s interface{}, elem interface{}) bool {
arrV := reflect.ValueOf(s)
if arrV.Kind() == reflect.Slice {
for i := 0; i < arrV.Len(); i++ {
// XXX - panics if slice element points to an unexported struct field
// see https://golang.org/pkg/reflect/#Value.Interface
if arrV.Index(i).Interface() == elem {
return true
}
}
}
return false
}
func Insert(slice []objects.Guild, index int, value objects.Guild) []objects.Guild {
// Grow the slice by one element.
slice = slice[0 : len(slice)+1]
// Use copy to move the upper part of the slice out of the way and open a hole.
copy(slice[index+1:], slice[index:])
// Store the new value.
slice[index] = value
// Return the result.
return slice
}