Skip to content

Commit

Permalink
examples: filter_wasm_go: Upgrade to support Go 1.22.5 and TinyGo 0.32
Browse files Browse the repository at this point in the history
Signed-off-by: JinXinWang <[email protected]>
  • Loading branch information
opencmit2 authored and edsiper committed Aug 27, 2024
1 parent 03f595b commit eea409c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 31 deletions.
11 changes: 5 additions & 6 deletions examples/filter_wasm_go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,21 @@ This source source tree provides an example of WASM filter program with WASI mod
Tested on

* TinyGo
* [tinygo](https://tinygo.org/) tinygo version 0.23.0 linux/amd64 (using go version go1.18.2 and LLVM version 14.0.0)
* [tinygo](https://tinygo.org/) tinygo version 0.24.0 linux/amd64 (using go version go1.18.2 and LLVM version 14.0.0)
* [tinygo](https://tinygo.org/) tinygo version 0.32.0 linux/amd64 (using go version go1.22.5 and LLVM version 18.1.2)

For Ubuntu, it's easy to install with:

```console
$ wget https://github.com/tinygo-org/tinygo/releases/download/v0.24.0/tinygo_0.24.0_amd64.deb
$ sudo dpkg -i tinygo_0.24.0_amd64.deb
$ wget https://github.com/tinygo-org/tinygo/releases/download/v0.32.0/tinygo_0.32.0_amd64.deb
$ sudo dpkg -i tinygo_0.32.0_amd64.deb
```

## How to build

Execute _tinygo build_ as follows:

```console
$ tinygo build -wasm-abi=generic -target=wasi -o filter.wasm filter.go
$ tinygo build -target=wasi -o filter.wasm filter.go
```

Finally, under the same directory, `*.wasm` file will be created:
Expand Down Expand Up @@ -52,12 +51,12 @@ Create fluent-bit configuration file as follows:
[FILTER]
Name wasm
match dummy.*
Event_Format json
WASM_Path /path/to/filter.wasm
Function_Name go_filter
accessible_paths .,/path/to/fluent-bit

[OUTPUT]
Name stdout
Match *

```
6 changes: 3 additions & 3 deletions examples/filter_wasm_go/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ func go_filter(tag *uint8, tag_len uint, time_sec uint, time_nsec uint, record *
obj.Set("time", arena.NewString(now.String()))
obj.Set("tag", arena.NewString(string(btag)))
obj.Set("original", arena.NewString(br))
s := obj.String()
s += string(rune(0)) // Note: explicit null terminator.

s := obj.String() + string(rune(0))
rv := []byte(s)

return &rv[0]
}

func main() {}
func main() {}
8 changes: 2 additions & 6 deletions examples/filter_wasm_go/go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
module filter_wasm_go

go 1.18
go 1.22.5

require (
github.com/valyala/fastjson v1.6.3 // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
)
require github.com/valyala/fastjson v1.6.3
16 changes: 0 additions & 16 deletions examples/filter_wasm_go/go.sum
Original file line number Diff line number Diff line change
@@ -1,18 +1,2 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/goccy/go-json v0.9.10 h1:hCeNmprSNLB8B8vQKWl6DpuH0t60oEs+TAk9a7CScKc=
github.com/goccy/go-json v0.9.10/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/valyala/fastjson v1.6.3 h1:tAKFnnwmeMGPbwJ7IwxcTPCNr3uIzoIj3/Fh90ra4xc=
github.com/valyala/fastjson v1.6.3/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=
github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU=
github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc=
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 comments on commit eea409c

Please sign in to comment.