github.com/wangyougui/gf/v2@v2.6.5/internal/utils/utils_array.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/wangyougui/gf.
     6  
     7  package utils
     8  
     9  import "reflect"
    10  
    11  // IsArray checks whether given value is array/slice.
    12  // Note that it uses reflect internally implementing this feature.
    13  func IsArray(value interface{}) bool {
    14  	rv := reflect.ValueOf(value)
    15  	kind := rv.Kind()
    16  	if kind == reflect.Ptr {
    17  		rv = rv.Elem()
    18  		kind = rv.Kind()
    19  	}
    20  	switch kind {
    21  	case reflect.Array, reflect.Slice:
    22  		return true
    23  	default:
    24  		return false
    25  	}
    26  }