Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking for null values #401

Open
iamsli opened this issue Jan 31, 2025 · 1 comment
Open

Checking for null values #401

iamsli opened this issue Jan 31, 2025 · 1 comment

Comments

@iamsli
Copy link
Contributor

iamsli commented Jan 31, 2025

with how gofish decodes Redfish responses, there's not an easy way to check if a value is actually null or the Go default for null (e.g. if a float is 0 or null, if a field is an empty string or does not exist)

Do you have suggestions? Am I missing something glaringly obvious?

@stmcginnis
Copy link
Owner

There's not really a great way that I'm aware of. The library would need to do something like using a *string type for all string fields like aws-sdk-go does. That can be more confusing, and a bigger change, than it's worth.

Another (pretty invasive) option would be to use something like Rust's Option pattern and have something like:

type Option[T any] struct {
	Some T
	None bool
}

With some custom JSON marshaling to figure out if there is a value present or not.

The simplest option might be to see where this is actually needed, then add something to that specific object's JSON marshaling to do that detection and set a flag or something.

I haven't run in to an issue myself where this has been necessary, but I could see it being necessary under certain conditions. But not enough to need to make major changes to the library.

I suppose one other option is to read in the RawJson of the object and do some string parsing for the presence of the value you care about. Kind of simplistic, but also simple enough that it could work in the places where you really need to know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants