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:
8
8
tinygo build -o ./examples/${name} /main.go.wasm -scheduler=none -target=wasi -wasm-abi=generic ./examples/${name} /main.go
9
9
10
10
build.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
12
12
13
13
lint :
14
14
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
9
9
10
10
11
11
``` golang
12
-
13
12
import (
14
13
" github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm"
15
14
" github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types"
16
15
)
17
16
18
17
var counter proxywasm.MetricCounter
19
18
20
- const metricName = " proxy_wasm_go.request_counter"
21
-
22
- type context struct { proxywasm.DefaultContext }
19
+ type metricRootContext struct { proxywasm.DefaultRootContext }
23
20
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 " )
27
24
return true
28
25
}
29
26
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 {
31
30
// increment the request counter when we receive request headers
32
- counter.Increment (1 )
31
+ counter.Increment (1 )
33
32
return types.ActionContinue
34
33
}
35
-
36
34
```
37
35
38
36
### requirements
Original file line number Diff line number Diff line change @@ -64,7 +64,7 @@ func TestE2E_helloworld(t *testing.T) {
64
64
out := stdErr .String ()
65
65
fmt .Println (out )
66
66
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 " ))
68
68
}
69
69
70
70
func TestE2E_http_auth_random (t * testing.T ) {
Original file line number Diff line number Diff line change 15
15
package main
16
16
17
17
import (
18
+ "math/rand"
19
+
18
20
"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm"
19
21
)
20
22
@@ -36,15 +38,18 @@ func newHelloWorld(contextID uint32) proxywasm.RootContext {
36
38
37
39
// override
38
40
func (ctx * helloWorld ) OnVMStart (int ) bool {
41
+ rand .Seed (proxywasm .GetCurrentTime ())
42
+
39
43
proxywasm .LogInfo ("proxy_on_vm_start from Go!" )
40
44
if err := proxywasm .SetTickPeriodMilliSeconds (tickMilliseconds ); err != nil {
41
45
proxywasm .LogCriticalf ("failed to set tick period: %v" , err )
42
46
}
47
+
43
48
return true
44
49
}
45
50
46
51
// override
47
52
func (ctx * helloWorld ) OnTick () {
48
53
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 () )
50
55
}
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ func TestHelloWorld_OnTick(t *testing.T) {
27
27
require .Greater (t , len (logs ), 0 )
28
28
msg := logs [len (logs )- 1 ]
29
29
30
- assert .True (t , strings .Contains (msg , "OnTick on " ))
30
+ assert .True (t , strings .Contains (msg , "It's " ))
31
31
}
32
32
33
33
func TestHelloWorld_OnVMStart (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments