Files
Reloader/internal/pkg/util/interface.go
faizanahmad055 b5c8705395 Refactor code
Signed-off-by: faizanahmad055 <faizan.ahmad55@outlook.com>
2026-05-11 16:18:53 +02:00

38 lines
782 B
Go

package util
import (
"reflect"
"strconv"
"github.com/sirupsen/logrus"
)
// InterfaceSlice converts an interface to an interface array
func InterfaceSlice(slice interface{}) []interface{} {
s := reflect.ValueOf(slice)
if s.Kind() != reflect.Slice {
logrus.Errorf("InterfaceSlice() given a non-slice type")
}
ret := make([]interface{}, s.Len())
for i := 0; i < s.Len(); i++ {
ret[i] = s.Index(i).Interface()
}
return ret
}
// ParseBool returns result in bool format after parsing
func ParseBool(value interface{}) bool {
if reflect.Bool == reflect.TypeOf(value).Kind() {
b, _ := value.(bool)
return b
} else if reflect.String == reflect.TypeOf(value).Kind() {
s, _ := value.(string)
result, _ := strconv.ParseBool(s)
return result
}
return false
}