cmp/options.go
func AllowUnexported(types ...interface{}) Option {
	if !supportAllowUnexported {
		panic("AllowUnexported is not supported on purego builds, Google App Engine Standard, or GopherJS")
	}
	m := make(map[reflect.Type]bool)
	for _, typ := range types {
		t := reflect.TypeOf(typ)
		if t.Kind() != reflect.Struct {
			panic(fmt.Sprintf("invalid struct type: %T", typ))
		}
		m[t] = true
	}
	return visibleStructs(m)
}
func AllowUnexported(types ...interface{}) Option {
	if !supportAllowUnexported {
		panic("AllowUnexported is not supported on purego builds, Google App Engine Standard, or GopherJS")
	}
	m := make(map[reflect.Type]bool)
	for _, typ := range types {
		t := reflect.TypeOf(typ)
		if t.Kind() != reflect.Struct {
			panic(fmt.Sprintf("invalid struct type: %T", typ))
		}
		m[t] = true
	}
	return visibleStructs(m)
}
func AllowUnexported ( types ... interface { } ) Option { if ! supportAllowUnexported { panic ( " " ) } m := make ( map [ reflect . Type ] bool ) for _ , typ := range types { t := reflect . TypeOf ( typ ) if t . Kind ( ) != reflect . Struct { panic ( fmt . Sprintf ( " " , typ ) ) } m [ t ] = true } return visibleStructs ( m ) }
// AllowUnexported returns an Option that forcibly allows operations on
// unexported fields in certain structs, which are specified by passing in a
// value of each struct type.
//
// Users of this option must understand that comparing on unexported fields
// from external packages is not safe since changes in the internal
// implementation of some external package may cause the result of Equal
// to unexpectedly change. However, it may be valid to use this option on types
// defined in an internal package where the semantic meaning of an unexported
// field is in the control of the user.
//
// In many cases, a custom Comparer should be used instead that defines
// equality as a function of the public API of a type rather than the underlying
// unexported implementation.
//
// For example, the reflect.Type documentation defines equality to be determined
// by the == operator on the interface (essentially performing a shallow pointer
// comparison) and most attempts to compare *regexp.Regexp types are interested
// in only checking that the regular expression strings are equal.
// Both of these are accomplished using Comparers:
//
//	Comparer(func(x, y reflect.Type) bool { return x == y })
//	Comparer(func(x, y *regexp.Regexp) bool { return x.String() == y.String() })
//
// In other cases, the cmpopts.IgnoreUnexported option can be used to ignore
// all unexported fields on specified struct types.
AllowUnexported returns an Option that forcibly allows operations on unexported fields in certain structs which are specified by passing in a value of each struct type . Users of this option must understand that comparing on unexported fields from external packages is not safe since changes in the internal implementation of some external package may cause the result of Equal to unexpectedly change . However it may be valid to use this option on types defined in an internal package where the semantic meaning of an unexported field is in the control of the user . In many cases a custom Comparer should be used instead that defines equality as a function of the public API of a type rather than the underlying unexported implementation . For example the reflect . Type documentation defines equality to be determined by the == operator on the interface ( essentially performing a shallow pointer comparison ) and most attempts to compare * regexp . Regexp types are interested in only checking that the regular expression strings are equal . Both of these are accomplished using Comparers : Comparer ( func ( x y reflect . Type ) bool { return x == y } ) Comparer ( func ( x y * regexp . Regexp ) bool { return x . String () == y . String () } ) In other cases the cmpopts . IgnoreUnexported option can be used to ignore all unexported fields on specified struct types .