'Is there any way to validate if input is passed in REGO language?
In REGO language how can we validate if an input exists? I got one way to do this.
package play
default hello = false
hello {
input.message
}
But is this the right approach? Or is there a better way?
Solution 1:[1]
No, that is the right way. In the rare case where you'll need to account for the possibility of input.message being set, but be assigned the value false, you could use unification to check for that:
package play
hello {
_ = input.message
}
But 99% of the times, your solution is what I'd go with.
Solution 2:[2]
package play
default inputcheck = false
inputcheck {input["message"]}
This returns true if the key 'message' exist in your input . Else it returns default false
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Devoops |
| Solution 2 | Vigneshraja M M |
