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 wanted to gauge interest in a method on the Scalar interface to expose the value via any/interface{} like:
typeScalarinterface {
…
AnyValue() any
…
}
Usage: This would greatly help scenarios where the user is intentionally serializing to another format (e.g. JSON) and would like to incur memory overhead.
For example, creating an array of anys for serialization. I know that String() can also be used for this, but it doesn't preserve the type.
I'm thinking that this also allows the user to recover the type via casting subsequently. However, it allows for handling the scalar value without casting of the Scalar value first.
@chrisirhc Thanks for filing this, I can see the benefit here if that's something people are looking for. Most of the Scalar types already have a value() method which returns an interface{}, it just isn't publicly available. In theory it should be possible to just make that externally visible to do this. Would you be willing to make the PR for it?
Yep, happy to do so. Thoughts on what to name the method? Does AnyValue() work ? I'd assume Value() conflicts or might be confusing since .Value is used to access typed scalar value.
Alternatives:
Describe the enhancement requested
I wanted to gauge interest in a method on the Scalar interface to expose the value via any/interface{} like:
Usage: This would greatly help scenarios where the user is intentionally serializing to another format (e.g. JSON) and would like to incur memory overhead.
For example, creating an array of anys for serialization. I know that
String()
can also be used for this, but it doesn't preserve the type.I'm thinking that this also allows the user to recover the type via casting subsequently. However, it allows for handling the scalar value without casting of the Scalar value first.
Example usage:
Today, this would large switch case statement to achieve this.
Let me know if I'm missing something.
Component(s)
Go
Related to #10972
The text was updated successfully, but these errors were encountered: