(inter interface{}, v *StringValidation)
| 74 | } |
| 75 | |
| 76 | func String(inter interface{}, v *StringValidation) (string, error) { |
| 77 | if inter == nil { |
| 78 | if v.TreatNullAsEmpty { |
| 79 | return ValidateStringProvided("", v) |
| 80 | } |
| 81 | return "", ErrorCannotBeNull(v.Required) |
| 82 | } |
| 83 | casted, castOk := inter.(string) |
| 84 | if !castOk { |
| 85 | if v.CastScalar { |
| 86 | if !cast.IsScalarType(inter) { |
| 87 | return "", ErrorInvalidPrimitiveType(inter, PrimTypeString, PrimTypeInt, PrimTypeFloat, PrimTypeBool) |
| 88 | } |
| 89 | casted = s.ObjFlatNoQuotes(inter) |
| 90 | } else if v.CastNumeric { |
| 91 | if !cast.IsNumericType(inter) { |
| 92 | return "", ErrorInvalidPrimitiveType(inter, PrimTypeString, PrimTypeInt, PrimTypeFloat) |
| 93 | } |
| 94 | casted = s.ObjFlatNoQuotes(inter) |
| 95 | } else if v.CastInt { |
| 96 | if !cast.IsIntType(inter) { |
| 97 | return "", ErrorInvalidPrimitiveType(inter, PrimTypeString, PrimTypeInt) |
| 98 | } |
| 99 | casted = s.ObjFlatNoQuotes(inter) |
| 100 | } else { |
| 101 | return "", ErrorInvalidPrimitiveType(inter, PrimTypeString) |
| 102 | } |
| 103 | } |
| 104 | return ValidateStringProvided(casted, v) |
| 105 | } |
| 106 | |
| 107 | func StringFromInterfaceMap(key string, iMap map[string]interface{}, v *StringValidation) (string, error) { |
| 108 | inter, ok := ReadInterfaceMapValue(key, iMap) |
no test coverage detected