MCPcopy Index your code
hub / github.com/cortexlabs/cortex / String

Function String

pkg/lib/configreader/string.go:76–105  ·  view source on GitHub ↗
(inter interface{}, v *StringValidation)

Source from the content-addressed store, hash-verified

74}
75
76func 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
107func StringFromInterfaceMap(key string, iMap map[string]interface{}, v *StringValidation) (string, error) {
108 inter, ok := ReadInterfaceMapValue(key, iMap)

Callers 1

StringFromInterfaceMapFunction · 0.70

Calls 6

IsScalarTypeFunction · 0.92
IsNumericTypeFunction · 0.92
IsIntTypeFunction · 0.92
ValidateStringProvidedFunction · 0.85
ErrorCannotBeNullFunction · 0.85

Tested by

no test coverage detected