This repository was archived by the owner on Apr 24, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +17
-14
lines changed Expand file tree Collapse file tree 5 files changed +17
-14
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ build.example:
88 tinygo build -o ./examples/${name} /main.go.wasm -scheduler=none -target=wasi -wasm-abi=generic ./examples/${name} /main.go
99
1010build.examples :
11- find ./examples -type f -name " main.go" | xargs -Ip tinygo build -o p.wasm -target=wasi -wasm-abi=generic p
11+ find ./examples -type f -name " main.go" | xargs -Ip tinygo build -o p.wasm -scheduler=none - target=wasi -wasm-abi=generic p
1212
1313lint :
1414 golangci-lint run --build-tags proxytest
Original file line number Diff line number Diff line change @@ -9,30 +9,28 @@ proxy-wasm-go-sdk is powered by [TinyGo](https://tinygo.org/) and does not suppo
99
1010
1111``` golang
12-
1312import (
1413 " github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm"
1514 " github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types"
1615)
1716
1817var counter proxywasm.MetricCounter
1918
20- const metricName = " proxy_wasm_go.request_counter"
21-
22- type context struct { proxywasm.DefaultContext }
19+ type metricRootContext struct { proxywasm.DefaultRootContext }
2320
24- func (ctx *context ) OnVMStart (int ) bool {
25- // initialize the new metric
26- counter, _ = proxywasm.DefineCounterMetric (metricName )
21+ func (ctx *metricRootContext ) OnVMStart (int ) bool {
22+ // initialize the metric
23+ counter = proxywasm.DefineCounterMetric (" proxy_wasm_go.request_counter " )
2724 return true
2825}
2926
30- func (ctx *context ) OnHttpRequestHeaders (int , bool ) types .Action {
27+ type metricHttpContext struct { proxywasm.DefaultHttpContext }
28+
29+ func (ctx *metricHttpContext ) OnHttpRequestHeaders (int , bool ) types .Action {
3130 // increment the request counter when we receive request headers
32- counter.Increment (1 )
31+ counter.Increment (1 )
3332 return types.ActionContinue
3433}
35-
3634```
3735
3836### requirements
Original file line number Diff line number Diff line change @@ -64,7 +64,7 @@ func TestE2E_helloworld(t *testing.T) {
6464 out := stdErr .String ()
6565 fmt .Println (out )
6666 assert .True (t , strings .Contains (out , "wasm log helloworld: proxy_on_vm_start from Go!" ))
67- assert .True (t , strings .Contains (out , "wasm log helloworld: OnTick on " ))
67+ assert .True (t , strings .Contains (out , "wasm log helloworld: It's " ))
6868}
6969
7070func TestE2E_http_auth_random (t * testing.T ) {
Original file line number Diff line number Diff line change 1515package main
1616
1717import (
18+ "math/rand"
19+
1820 "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm"
1921)
2022
@@ -36,15 +38,18 @@ func newHelloWorld(contextID uint32) proxywasm.RootContext {
3638
3739// override
3840func (ctx * helloWorld ) OnVMStart (int ) bool {
41+ rand .Seed (proxywasm .GetCurrentTime ())
42+
3943 proxywasm .LogInfo ("proxy_on_vm_start from Go!" )
4044 if err := proxywasm .SetTickPeriodMilliSeconds (tickMilliseconds ); err != nil {
4145 proxywasm .LogCriticalf ("failed to set tick period: %v" , err )
4246 }
47+
4348 return true
4449}
4550
4651// override
4752func (ctx * helloWorld ) OnTick () {
4853 t := proxywasm .GetCurrentTime ()
49- proxywasm .LogInfof ("OnTick on %d, it's %d" , ctx . contextID , t )
54+ proxywasm .LogInfof ("It's %d: random value: %d" , t , rand . Uint64 () )
5055}
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ func TestHelloWorld_OnTick(t *testing.T) {
2727 require .Greater (t , len (logs ), 0 )
2828 msg := logs [len (logs )- 1 ]
2929
30- assert .True (t , strings .Contains (msg , "OnTick on " ))
30+ assert .True (t , strings .Contains (msg , "It's " ))
3131}
3232
3333func TestHelloWorld_OnVMStart (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments