Skip to content

Commit 95d009d

Browse files
authored
Update Getting-Started.md
1 parent 85ffe57 commit 95d009d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

docs/Getting-Started.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ type Segment struct {
2020
}
2121
```
2222

23+
#### Compile step
24+
2325
First what we need to do is to create a way users will be creating, editing (and maybe deleted) filter rules, but this is out of scope for this article. Let's assume that we have some kind of Web interface where users can do all of this task. On creation or deletion of rules, we much check if rules are written correctly. And we want to give the user access to `Request` fields and only these fields.
2426

2527
```go
@@ -35,10 +37,16 @@ program, err = expr.Compile(rule, expr.Env(&Request{}))
3537

3638
By passing `&Request{}` as env into compile method we turned on type checking, now if users make an error in field or compare strings with integers, he will get an error. Now users can save expressions.
3739

40+
#### Example of an expression
41+
3842
```coffeescript
3943
all(Ticket.Segments, {.Origin == Location}) and Date.Before(Ticket.Segments[0].Date)
4044
```
4145

46+
<p align="center">👐</p>
47+
48+
#### Runtime step
49+
4250
Now we need to implement the execution of our compiled program. On each request, we have some kind of filter loop.
4351

4452
```go
@@ -52,6 +60,8 @@ if !output.(bool) {
5260
}
5361
```
5462

63+
#### Helpers
64+
5565
Now let's some add a function for repetitive tasks.
5666

5767
```go
@@ -70,6 +80,8 @@ Now users can use functions inside expressions.
7080
SameLocation() and Date.Before(Ticket.Segments[0].Date)
7181
```
7282

83+
#### Operator override
84+
7385
Much better. But using time's package methods isn't pretty. What if we can override operators? And we can! Let's describe another function.
7486

7587
```go

0 commit comments

Comments
 (0)