github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/pkg/rego/convert/slice.go (about)

     1  package convert
     2  
     3  import (
     4  	"reflect"
     5  )
     6  
     7  func SliceToRego(inputValue reflect.Value) []interface{} {
     8  
     9  	// make sure we have a struct literal
    10  	for inputValue.Type().Kind() == reflect.Ptr {
    11  		if inputValue.IsNil() {
    12  			return nil
    13  		}
    14  		inputValue = inputValue.Elem()
    15  	}
    16  	if inputValue.Type().Kind() != reflect.Slice {
    17  		panic("not a slice")
    18  	}
    19  
    20  	output := make([]interface{}, inputValue.Len())
    21  
    22  	for i := 0; i < inputValue.Len(); i++ {
    23  		val := inputValue.Index(i)
    24  		if val.Type().Kind() == reflect.Ptr && val.IsZero() {
    25  			output[i] = nil
    26  			continue
    27  		}
    28  		output[i] = anonymousToRego(val)
    29  	}
    30  
    31  	return output
    32  }