MCPcopy Create free account
hub / github.com/cortexlabs/cortex / InterfaceToInt32Downcast

Function InterfaceToInt32Downcast

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

Source from the content-addressed store, hash-verified

175}
176
177func InterfaceToInt32Downcast(in interface{}) (int32, bool) {
178 var ok bool
179 if in, ok = JSONNumberToIntOrFloat(in); !ok {
180 return 0, false
181 }
182
183 switch casted := in.(type) {
184 case int8:
185 return int32(casted), true
186 case int16:
187 return int32(casted), true
188 case int32:
189 return casted, true
190 case int:
191 if val := int32(casted); int(val) == casted {
192 return val, true
193 }
194 case int64:
195 if val := int32(casted); int64(val) == casted {
196 return val, true
197 }
198 case float32:
199 if val := int32(casted); float32(val) == casted {
200 return val, true
201 }
202 case float64:
203 if val := int32(casted); float64(val) == casted {
204 return val, true
205 }
206 }
207 return 0, false
208}
209
210func InterfaceToInt(in interface{}) (int, bool) {
211 var ok bool

Callers

nothing calls this directly

Calls 1

JSONNumberToIntOrFloatFunction · 0.85

Tested by

no test coverage detected