-
-
Notifications
You must be signed in to change notification settings - Fork 457
Open
Description
I have the following struct that serves as an environment input:
type struct InputStruct {
Enabled *bool `json:"enabled"`
}
var v InputStruct
// unmarshal json into struct v
// ...
env := map[string]any {
"v": v,
}
I need to write an expression that evaluates the Enabled
field and returns:
- "default" when the pointer is nil
- "enabled" when the dereferenced value is true
- "disabled" when the dereferenced value is false
The best solution I've come up with so far is:
v.Enabled == nil ? 'default' : ( (v.Enabled??'nil') ? 'enabled' : 'disabled' )
Is this the most idiomatic way to handle this case in Expr?
Metadata
Metadata
Assignees
Labels
No labels