gitee.com/quant1x/gox@v1.21.2/api/reflect.go (about)

     1  package api
     2  
     3  import "reflect"
     4  
     5  func GetConcreteContainerInnerType(in reflect.Type) (inInnerWasPointer bool, inInnerType reflect.Type) {
     6  	inInnerType = in.Elem()
     7  	inInnerWasPointer = false
     8  	if inInnerType.Kind() == reflect.Ptr {
     9  		inInnerWasPointer = true
    10  		inInnerType = inInnerType.Elem()
    11  	}
    12  	return inInnerWasPointer, inInnerType
    13  }
    14  
    15  func GetConcreteReflectValueAndType(in any) (reflect.Value, reflect.Type) {
    16  	value := reflect.ValueOf(in)
    17  	if value.Kind() == reflect.Ptr {
    18  		value = value.Elem()
    19  	}
    20  	return value, value.Type()
    21  }
    22  
    23  var errorInterface = reflect.TypeOf((*error)(nil)).Elem()
    24  
    25  func IsErrorType(outType reflect.Type) bool {
    26  	if outType.Kind() != reflect.Interface {
    27  		return false
    28  	}
    29  
    30  	return outType.Implements(errorInterface)
    31  }