// Copyright © 2014 Steve Francia <spf@spf13.com>. // // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file.
package cast import ( ) var kindNames = []string{ reflect.String: "string", reflect.Bool: "bool", reflect.Int: "int", reflect.Int8: "int8", reflect.Int16: "int16", reflect.Int32: "int32", reflect.Int64: "int64", reflect.Uint: "uint", reflect.Uint8: "uint8", reflect.Uint16: "uint16", reflect.Uint32: "uint32", reflect.Uint64: "uint64", reflect.Float32: "float32", reflect.Float64: "float64", } var kinds = map[reflect.Kind]func(reflect.Value) any{ reflect.String: func( reflect.Value) any { return .String() }, reflect.Bool: func( reflect.Value) any { return .Bool() }, reflect.Int: func( reflect.Value) any { return int(.Int()) }, reflect.Int8: func( reflect.Value) any { return int8(.Int()) }, reflect.Int16: func( reflect.Value) any { return int16(.Int()) }, reflect.Int32: func( reflect.Value) any { return int32(.Int()) }, reflect.Int64: func( reflect.Value) any { return .Int() }, reflect.Uint: func( reflect.Value) any { return uint(.Uint()) }, reflect.Uint8: func( reflect.Value) any { return uint8(.Uint()) }, reflect.Uint16: func( reflect.Value) any { return uint16(.Uint()) }, reflect.Uint32: func( reflect.Value) any { return uint32(.Uint()) }, reflect.Uint64: func( reflect.Value) any { return .Uint() }, reflect.Float32: func( reflect.Value) any { return float32(.Float()) }, reflect.Float64: func( reflect.Value) any { return .Float() }, } // resolveAlias attempts to resolve a named type to its underlying basic type (if possible). // // Pointers are expected to be indirected by this point. func resolveAlias( any) (any, bool) { if == nil { return nil, false } := reflect.TypeOf() // Not a named type if .Name() == "" || slices.Contains(kindNames, .Name()) { return , false } , := kinds[.Kind()] if ! { // Not a supported kind return , false } := reflect.ValueOf() return (), true }