You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think this should fold into #54297
Panic is not a general purpose error handler, and the existing must variants are intended for global values that the programmer knows cannot fail. User provided json does not fall into that category.
Proposal Details
It would be more convinced if we could have methods
MustFloat64
andMustInt64
that wrapsFloat64
andInt64
.Why
Assume we need to copy some field from a json object to another struct:
A
tmpNum
is necessary to receive the returned value fromInt64()
. But if we have aMustInt64
, we could do the same thing like:If the
dest
has multi fields that comes from differentjson.Number
, we need to declare multi tmp variables for each field.And such expression is not allowed because
Dest.Foo
isint
butInt64()
returns a Int64With
MustInt64
, this expression is valid:How
A simple wrapper for
Float64
andInt64
:Question
panic
if this field is empty string?panic
or return 0 whenParseInt
/ParseFloat
failed?The text was updated successfully, but these errors were encountered: