diff --git a/default_values.go b/default_values.go index ab1d24b..396bf70 100644 --- a/default_values.go +++ b/default_values.go @@ -63,3 +63,52 @@ func Float64OrDefault(v *float64) float64 { } return 0.0 } + +func NilSafeInt32OrDefault(val *interface{}) int32 { + if *val != nil { + return (*val).(int32) + } + return 0 +} + +func NilSafeInt64OrDefault(val *interface{}) int64 { + if *val != nil { + return (*val).(int64) + } + return 0 +} + +func NilSafeUint32OrDefault(val *interface{}) uint32 { + if *val != nil { + return (*val).(uint32) + } + return 0 +} + +func NilSafeUint64OrDefault(val *interface{}) uint64 { + if *val != nil { + return (*val).(uint64) + } + return 0 +} + +func NilSafeFloat32OrDefault(val *interface{}) float32 { + if *val != nil { + return (*val).(float32) + } + return 0.0 +} + +func NilSafeFloat64OrDefault(val *interface{}) float64 { + if *val != nil { + return (*val).(float64) + } + return 0.0 +} + +func NilSafeStringOrDefault(val *interface{}) string { + if *val != nil { + return (*val).(string) + } + return "" +}