MCPcopy
hub / github.com/cortexlabs/cortex / InterfaceToInt32

Function InterfaceToInt32

pkg/lib/cast/interface.go:152–175  ·  view source on GitHub ↗
(in interface{})

Source from the content-addressed store, hash-verified

150}
151
152func InterfaceToInt32(in interface{}) (int32, bool) {
153 var ok bool
154 if in, ok = JSONNumberToInt(in); !ok {
155 return 0, false
156 }
157
158 switch casted := in.(type) {
159 case int8:
160 return int32(casted), true
161 case int16:
162 return int32(casted), true
163 case int32:
164 return casted, true
165 case int:
166 if val := int32(casted); int(val) == casted {
167 return val, true
168 }
169 case int64:
170 if val := int32(casted); int64(val) == casted {
171 return val, true
172 }
173 }
174 return 0, false
175}
176
177func InterfaceToInt32Downcast(in interface{}) (int32, bool) {
178 var ok bool

Callers 4

Int32PtrFunction · 0.92
Int32ListFunction · 0.92
Int32Function · 0.92
InterfaceToInt32SliceFunction · 0.85

Calls 1

JSONNumberToIntFunction · 0.85

Tested by

no test coverage detected