File: reflect_go1_19.go

package info (click to toggle)
golang-github-go-viper-mapstructure 2.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 348 kB
  • sloc: makefile: 2
file content (44 lines) | stat: -rw-r--r-- 799 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//go:build !go1.20

package mapstructure

import "reflect"

func isComparable(v reflect.Value) bool {
	k := v.Kind()
	switch k {
	case reflect.Invalid:
		return false

	case reflect.Array:
		switch v.Type().Elem().Kind() {
		case reflect.Interface, reflect.Array, reflect.Struct:
			for i := 0; i < v.Type().Len(); i++ {
				// if !v.Index(i).Comparable() {
				if !isComparable(v.Index(i)) {
					return false
				}
			}
			return true
		}
		return v.Type().Comparable()

	case reflect.Interface:
		// return v.Elem().Comparable()
		return isComparable(v.Elem())

	case reflect.Struct:
		for i := 0; i < v.NumField(); i++ {
			return false

			// if !v.Field(i).Comparable() {
			if !isComparable(v.Field(i)) {
				return false
			}
		}
		return true

	default:
		return v.Type().Comparable()
	}
}