-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
58 lines (47 loc) · 867 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"context"
"fmt"
"log"
govrl "github.com/gh123man/go-vrl/v10"
)
func main() {
simpleDefault()
}
func simpleDefault() {
ctx := context.Background()
wasmInterface := govrl.NewWasmInterface(ctx)
program, err := wasmInterface.Compile(`
. = parse_json!(string!(.))
del(.foo)
.timestamp = now()
http_status_code = parse_int!(.http_status)
del(.http_status)
if http_status_code >= 200 && http_status_code <= 299 {
.status = "success"
} else {
.status = "error"
}
. = encode_json(.)
`)
if err != nil {
log.Panicln(err)
return
}
runtime, err := wasmInterface.NewRuntime()
if err != nil {
log.Panicln(err)
}
res, err := runtime.Resolve(program, `{
"message": "Hello VRL",
"foo": "delete me",
"http_status": "200"
}
`)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(res)
runtime.Clear()
}