-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b9f7a1
commit 63036ba
Showing
3 changed files
with
83 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/nurettintopal/rule" | ||
) | ||
|
||
func main() { | ||
input := `{ | ||
"country": "Turkey", | ||
"city": "Istanbul", | ||
"district": "Kadikoy", | ||
"population": 2000000.00, | ||
"language": "Turkish" | ||
}` | ||
|
||
rules := `{ | ||
"conditions":[ | ||
{ | ||
"all":[ | ||
{ | ||
"field":"external.score", | ||
"operator":"greaterThan", | ||
"value":4 | ||
}, | ||
{ | ||
"field":"population", | ||
"operator":"custom.eligible", | ||
"value": true | ||
} | ||
], | ||
"any":[ | ||
{ | ||
"field":"country", | ||
"operator":"in", | ||
"value": ["Turkey", "England"] | ||
} | ||
] | ||
} | ||
] | ||
}` | ||
|
||
custom := map[string]rule.CustomOperation{ | ||
"score": &CustomCountryScore{}, | ||
"eligible": &CustomRuleEligible{}, | ||
} | ||
|
||
if rule.Execute(input, rules, custom) { | ||
fmt.Printf("Rules have been executed. it passed!") | ||
} else { | ||
fmt.Printf("Rules have been executed. it failed!") | ||
} | ||
} | ||
|
||
// CustomOperation implementations | ||
type CustomRuleEligible struct{} | ||
|
||
func (o *CustomRuleEligible) Execute(input, value interface{}) interface{} { | ||
fmt.Println("DEBUG: CustomRuleEligible Execute", input, value) | ||
return true | ||
} | ||
|
||
// CustomOperation implementations | ||
type CustomCountryScore struct{} | ||
|
||
func (o *CustomCountryScore) Execute(input, value interface{}) interface{} { | ||
fmt.Println("DEBUG: CustomCountryScore Execute", input, value) | ||
//TODO: there should be some implementation here. | ||
return 4.6 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters