418 }
419 v.Targets = t
420 }
421 if w, ok := t["limit"].(interface{}); ok {422 var lmt ServiceResourceLimit
423 if err := remarshal(w, &lmt); err != nil {
424 return err
411 if w, ok := t["memory"].(int); ok {
412 v.Memory = w
413 }
414 if w, ok := t["targets"].(interface{}); ok {415 var t ServiceScaleTargets
416 if err := remarshal(w, &t); err != nil {
417 return err
401 if w, ok := t["cpu"].(int); ok {
402 v.Cpu = w
403 }
404 if w, ok := t["gpu"].(interface{}); ok {405 var g ServiceScaleGpu
406 if err := remarshal(w, &g); err != nil {
407 return err
391 }
392 v.Count = c
393 case map[interface{}]interface{}:
394 if w, ok := t["count"].(interface{}); ok {395 var c ServiceScaleCount
396 if err := remarshal(w, &c); err != nil {
397 return err
The type assertion x.(SomeInterface)
, when x
already has type SomeInterface
,
can only fail if x is nil.
Usually, this is left-over code from when x
had a different type, and you can
safely delete the type assertion. If you want to check that x
is not nil
,
consider being explicit and using an actual if x != nil
comparison instead of
relying on the type assertion panicking.
func foo(x i1) {
_ = x.(i1) // will panic if x is nil
}
func foo(x i1) {
if x != nil {
// ...
}
}