package magic import ( "reflect" "strconv" "strings" ) var ( pathValueConvertTable = map[reflect.Kind]func(string) (any, error){ reflect.String: func(s string) (any, error) { return s, nil }, reflect.Bool: func(s string) (any, error) { switch strings.ToLower(s) { case "0", "false", "no", "n": return false, nil case "1", "true", "yes", "y": return true, nil } return nil, InvalidPathValueType{Kind: reflect.Bool, Value: s} }, reflect.Float64: func(s string) (any, error) { if v, err := strconv.ParseFloat(s, 64); err != nil { return nil, err } else { return v, nil } }, reflect.Float32: func(s string) (any, error) { if v, err := strconv.ParseFloat(s, 32); err != nil { return nil, err } else { return float32(v), nil } }, reflect.Int: func(s string) (any, error) { if v, err := strconv.ParseInt(s, 10, 64); err != nil { return nil, err } else { return int(v), nil } }, reflect.Int8: func(s string) (any, error) { if v, err := strconv.ParseInt(s, 10, 8); err != nil { return nil, err } else { return int8(v), nil } }, reflect.Int16: func(s string) (any, error) { if v, err := strconv.ParseInt(s, 10, 16); err != nil { return nil, err } else { return int8(v), nil } }, reflect.Int32: func(s string) (any, error) { if v, err := strconv.ParseInt(s, 10, 32); err != nil { return nil, err } else { return int8(v), nil } }, reflect.Int64: func(s string) (any, error) { if v, err := strconv.ParseInt(s, 10, 64); err != nil { return nil, err } else { return int8(v), nil } }, reflect.Uint: func(s string) (any, error) { if v, err := strconv.ParseUint(s, 10, 64); err != nil { return nil, err } else { return uint(v), nil } }, reflect.Uint8: func(s string) (any, error) { if v, err := strconv.ParseUint(s, 10, 8); err != nil { return nil, err } else { return uint8(v), nil } }, reflect.Uint16: func(s string) (any, error) { if v, err := strconv.ParseUint(s, 10, 16); err != nil { return nil, err } else { return uint16(v), nil } }, reflect.Uint32: func(s string) (any, error) { if v, err := strconv.ParseUint(s, 10, 32); err != nil { return nil, err } else { return uint32(v), nil } }, reflect.Uint64: func(s string) (any, error) { if v, err := strconv.ParseUint(s, 10, 64); err != nil { return nil, err } else { return v, nil } }, } )