Aiswarya M
Aiswarya M

Reputation: 1

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?

Upvotes: 0

Views: 1112

Answers (2)

Vigneshraja M M
Vigneshraja M M

Reputation: 1

package play

default inputcheck = false

inputcheck {input["message"]}

This returns true if the key 'message' exist in your input . Else it returns default false

Upvotes: 0

Devoops
Devoops

Reputation: 2360

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.

Upvotes: 0

Related Questions