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

Function StringPtr

pkg/lib/configreader/string_ptr.go:96–123  ·  view source on GitHub ↗
(inter interface{}, v *StringPtrValidation)

Source from the content-addressed store, hash-verified

94}
95
96func StringPtr(inter interface{}, v *StringPtrValidation) (*string, error) {
97 if inter == nil {
98 return ValidateStringPtrProvided(nil, v)
99 }
100 casted, castOk := inter.(string)
101 if !castOk {
102 if v.CastScalar {
103 if !cast.IsScalarType(inter) {
104 return nil, ErrorInvalidPrimitiveType(inter, PrimTypeString, PrimTypeInt, PrimTypeFloat, PrimTypeBool)
105 }
106 casted = s.ObjFlatNoQuotes(inter)
107 } else if v.CastNumeric {
108 if !cast.IsNumericType(inter) {
109 return nil, ErrorInvalidPrimitiveType(inter, PrimTypeString, PrimTypeInt, PrimTypeFloat)
110 }
111 casted = s.ObjFlatNoQuotes(inter)
112 } else if v.CastInt {
113 if !cast.IsIntType(inter) {
114 return nil, ErrorInvalidPrimitiveType(inter, PrimTypeString, PrimTypeInt)
115 }
116 casted = s.ObjFlatNoQuotes(inter)
117 } else {
118 return nil, ErrorInvalidPrimitiveType(inter, PrimTypeString)
119 }
120 }
121
122 return ValidateStringPtrProvided(&casted, v)
123}
124
125func StringPtrFromInterfaceMap(key string, iMap map[string]interface{}, v *StringPtrValidation) (*string, error) {
126 inter, ok := ReadInterfaceMapValue(key, iMap)

Callers 1

Calls 5

IsScalarTypeFunction · 0.92
IsNumericTypeFunction · 0.92
IsIntTypeFunction · 0.92

Tested by

no test coverage detected