utils_array.go 666 B

1234567891011121314151617181920212223242526
  1. // Copyright 2019 gf Author(https://github.com/gogf/gf). 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/gogf/gf.
  6. package utils
  7. import "reflect"
  8. // IsArray checks whether given value is array/slice.
  9. // Note that it uses reflect internally implementing this feature.
  10. func IsArray(value interface{}) bool {
  11. rv := reflect.ValueOf(value)
  12. kind := rv.Kind()
  13. if kind == reflect.Ptr {
  14. rv = rv.Elem()
  15. kind = rv.Kind()
  16. }
  17. switch kind {
  18. case reflect.Array, reflect.Slice:
  19. return true
  20. default:
  21. return false
  22. }
  23. }