Skip to content

Commit e9861eb

Browse files
authored
Complete the doc comment for all exported API. (tetratelabs#188)
Signed-off-by: Takeshi Yoneda <[email protected]>
1 parent 715c563 commit e9861eb

File tree

22 files changed

+187
-184
lines changed

22 files changed

+187
-184
lines changed

README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext {
2121
}
2222

2323
type pluginContext struct {
24-
types.DefaultPluginContext
2524
counter proxywasm.MetricCounter
2625
}
2726

@@ -31,7 +30,6 @@ func (*pluginContext) NewHttpContext(contextID uint32) types.HttpContext {
3130
}
3231

3332
type httpContext struct {
34-
types.DefaultHttpContext
3533
counter proxywasm.MetricCounter
3634
}
3735

@@ -54,7 +52,7 @@ Please follow the official instruction [here](https://tinygo.org/getting-started
5452
| proxy-wasm-go-sdk| proxy-wasm ABI version |istio/proxyv2| Envoy upstream|
5553
|:-------------:|:-------------:|:-------------:|:-------------:|
5654
| main | 0.2.0| 1.9, 1.10 | 1.18 |
57-
| v0.3.0 | 0.2.0| 1.8, 1.9 | 1.17 |
55+
| v0.3.0 | 0.2.0| 1.9, 1.10 | 1.18 |
5856

5957
## Development
6058

examples/dispatch_call_on_tick/main.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,25 @@ func main() {
2525
proxywasm.SetVMContext(&vmContext{})
2626
}
2727

28-
type vmContext struct{}
29-
30-
// Implement types.VMContext.
31-
func (*vmContext) OnVMStart(vmConfigurationSize int) types.OnVMStartStatus {
32-
return types.OnVMStartStatusOK
28+
type vmContext struct {
29+
// Embed the default VM context here,
30+
// so that we don't need to reimplement all the methods.
31+
types.DefaultVMContext
3332
}
3433

35-
// Implement types.VMContext.
34+
// Override types.DefaultVMContext.
3635
func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext {
3736
return &pluginContext{contextID: contextID}
3837
}
3938

4039
type pluginContext struct {
41-
// Embed the default root context here,
40+
// Embed the default plugin context here,
4241
// so that we don't need to reimplement all the methods.
4342
types.DefaultPluginContext
4443
contextID uint32
4544
}
4645

47-
// Override DefaultPluginContext.
46+
// Override types.DefaultPluginContext.
4847
func (ctx *pluginContext) OnPluginStart(vmConfigurationSize int) types.OnPluginStartStatus {
4948
if err := proxywasm.SetTickPeriodMilliSeconds(tickMilliseconds); err != nil {
5049
proxywasm.LogCriticalf("failed to set tick period: %v", err)
@@ -54,7 +53,7 @@ func (ctx *pluginContext) OnPluginStart(vmConfigurationSize int) types.OnPluginS
5453
return types.OnPluginStartStatusOK
5554
}
5655

57-
// Override DefaultPluginContext.
56+
// Override types.DefaultPluginContext.
5857
func (ctx *pluginContext) OnTick() {
5958
hs := [][2]string{
6059
{":method", "GET"}, {":authority", "some_authority"}, {":path", "/path/to/service"}, {"accept", "*/*"},

examples/foreign_call_on_tick/main.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,26 @@ func main() {
2727
proxywasm.SetVMContext(&vmContext{})
2828
}
2929

30-
type vmContext struct{}
31-
32-
// Implement types.VMContext.
33-
func (*vmContext) OnVMStart(vmConfigurationSize int) types.OnVMStartStatus {
34-
return types.OnVMStartStatusOK
30+
type vmContext struct {
31+
// Embed the default VM context here,
32+
// so that we don't need to reimplement all the methods.
33+
types.DefaultVMContext
3534
}
3635

37-
// Implement types.VMContext.
36+
// Override types.DefaultVMContext.
3837
func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext {
3938
return &pluginContext{}
4039
}
4140

4241
type pluginContext struct {
43-
// Embed the default root context here,
42+
// Embed the default plugin context here,
4443
// so that we don't need to reimplement all the methods.
4544
types.DefaultPluginContext
4645
contextID uint32
4746
callNum uint32
4847
}
4948

50-
// Override DefaultPluginContext.
49+
// Override types.DefaultPluginContext.
5150
func (ctx *pluginContext) OnPluginStart(vmConfigurationSize int) types.OnPluginStartStatus {
5251
if err := proxywasm.SetTickPeriodMilliSeconds(tickMilliseconds); err != nil {
5352
proxywasm.LogCriticalf("failed to set tick period: %v", err)
@@ -57,7 +56,7 @@ func (ctx *pluginContext) OnPluginStart(vmConfigurationSize int) types.OnPluginS
5756
return types.OnPluginStartStatusOK
5857
}
5958

60-
// Override DefaultPluginContext.
59+
// Override types.DefaultPluginContext.
6160
func (ctx *pluginContext) OnTick() {
6261
ctx.callNum++
6362
ret, err := proxywasm.CallForeignFunction("compress", []byte("hello world!"))

examples/helloworld/main.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,25 @@ func main() {
2828
proxywasm.SetVMContext(&vmContext{})
2929
}
3030

31-
type vmContext struct{}
32-
33-
// Implement types.VMContext.
34-
func (*vmContext) OnVMStart(vmConfigurationSize int) types.OnVMStartStatus {
35-
return types.OnVMStartStatusOK
31+
type vmContext struct {
32+
// Embed the default VM context here,
33+
// so that we don't need to reimplement all the methods.
34+
types.DefaultVMContext
3635
}
3736

38-
// Implement types.VMContext.
37+
// Override types.DefaultVMContext.
3938
func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext {
4039
return &helloWorld{}
4140
}
4241

4342
type helloWorld struct {
44-
// Embed the default root context here,
43+
// Embed the default plugin context here,
4544
// so that we don't need to reimplement all the methods.
4645
types.DefaultPluginContext
4746
contextID uint32
4847
}
4948

50-
// Override DefaultPluginContext.
49+
// Override types.DefaultPluginContext.
5150
func (ctx *helloWorld) OnPluginStart(vmConfigurationSize int) types.OnPluginStartStatus {
5251
rand.Seed(time.Now().UnixNano())
5352

@@ -59,7 +58,7 @@ func (ctx *helloWorld) OnPluginStart(vmConfigurationSize int) types.OnPluginStar
5958
return types.OnPluginStartStatusOK
6059
}
6160

62-
// Override DefaultPluginContext.
61+
// Override types.DefaultPluginContext.
6362
func (ctx *helloWorld) OnTick() {
6463
t := time.Now().UnixNano()
6564
proxywasm.LogInfof("It's %d: random value: %d", t, rand.Uint64())

examples/http_auth_random/main.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,24 @@ func main() {
2727
proxywasm.SetVMContext(&vmContext{})
2828
}
2929

30-
type vmContext struct{}
31-
32-
// Implement types.VMContext.
33-
func (*vmContext) OnVMStart(vmConfigurationSize int) types.OnVMStartStatus {
34-
return types.OnVMStartStatusOK
30+
type vmContext struct {
31+
// Embed the default VM context here,
32+
// so that we don't need to reimplement all the methods.
33+
types.DefaultVMContext
3534
}
3635

37-
// Implement types.VMContext.
36+
// Override types.DefaultVMContext.
3837
func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext {
3938
return &pluginContext{}
4039
}
4140

4241
type pluginContext struct {
43-
// Embed the default root context here,
42+
// Embed the default plugin context here,
4443
// so that we don't need to reimplement all the methods.
4544
types.DefaultPluginContext
4645
}
4746

48-
// Override DefaultPluginContext.
47+
// Override types.DefaultPluginContext.
4948
func (*pluginContext) NewHttpContext(contextID uint32) types.HttpContext {
5049
return &httpAuthRandom{contextID: contextID}
5150
}
@@ -57,7 +56,7 @@ type httpAuthRandom struct {
5756
contextID uint32
5857
}
5958

60-
// Override DefaultHttpContext.
59+
// Override types.DefaultHttpContext.
6160
func (ctx *httpAuthRandom) OnHttpRequestHeaders(numHeaders int, endOfStream bool) types.Action {
6261
hs, err := proxywasm.GetHttpRequestHeaders()
6362
if err != nil {

examples/http_body/main.go

+12-13
Original file line numberDiff line numberDiff line change
@@ -29,34 +29,33 @@ func main() {
2929
proxywasm.SetVMContext(&vmContext{})
3030
}
3131

32-
type vmContext struct{}
33-
34-
// Implement types.VMContext.
35-
func (*vmContext) OnVMStart(vmConfigurationSize int) types.OnVMStartStatus {
36-
return types.OnVMStartStatusOK
32+
type vmContext struct {
33+
// Embed the default VM context here,
34+
// so that we don't need to reimplement all the methods.
35+
types.DefaultVMContext
3736
}
3837

39-
// Implement types.VMContext.
38+
// Override types.DefaultVMContext.
4039
func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext {
4140
return &pluginContext{}
4241
}
4342

4443
type pluginContext struct {
45-
// Embed the default root context here,
44+
// Embed the default plugin context here,
4645
// so that we don't need to reimplement all the methods.
4746
types.DefaultPluginContext
4847
shouldEchoBody bool
4948
}
5049

51-
// Override DefaultPluginContext.
50+
// Override types.DefaultPluginContext.
5251
func (ctx *pluginContext) NewHttpContext(contextID uint32) types.HttpContext {
5352
if ctx.shouldEchoBody {
5453
return &echoBodyContext{}
5554
}
5655
return &setBodyContext{}
5756
}
5857

59-
// Override DefaultPluginContext.
58+
// Override types.DefaultPluginContext.
6059
func (ctx *pluginContext) OnPluginStart(pluginConfigurationSize int) types.OnPluginStartStatus {
6160
data, err := proxywasm.GetPluginConfiguration(pluginConfigurationSize)
6261
if err != nil {
@@ -74,7 +73,7 @@ type setBodyContext struct {
7473
bufferOperation string
7574
}
7675

77-
// Override DefaultHttpContext.
76+
// Override types.DefaultHttpContext.
7877
func (ctx *setBodyContext) OnHttpRequestHeaders(numHeaders int, endOfStream bool) types.Action {
7978
if _, err := proxywasm.GetHttpRequestHeader("content-length"); err != nil {
8079
if err := proxywasm.SendHttpResponse(400, nil, []byte("content must be provided")); err != nil {
@@ -100,7 +99,7 @@ func (ctx *setBodyContext) OnHttpRequestHeaders(numHeaders int, endOfStream bool
10099
return types.ActionContinue
101100
}
102101

103-
// Override DefaultHttpContext.
102+
// Override types.DefaultHttpContext.
104103
func (ctx *setBodyContext) OnHttpRequestBody(bodySize int, endOfStream bool) types.Action {
105104
ctx.totalRequestBodySize += bodySize
106105
if !endOfStream {
@@ -131,13 +130,13 @@ func (ctx *setBodyContext) OnHttpRequestBody(bodySize int, endOfStream bool) typ
131130
}
132131

133132
type echoBodyContext struct {
134-
// mbed the default root context
133+
// mbed the default plugin context
135134
// so that you don't need to reimplement all the methods by yourself.
136135
types.DefaultHttpContext
137136
totalRequestBodySize int
138137
}
139138

140-
// Override DefaultHttpContext.
139+
// Override types.DefaultHttpContext.
141140
func (ctx *echoBodyContext) OnHttpRequestBody(bodySize int, endOfStream bool) types.Action {
142141
ctx.totalRequestBodySize += bodySize
143142
if !endOfStream {

examples/http_headers/main.go

+10-11
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,24 @@ func main() {
2323
proxywasm.SetVMContext(&vmContext{})
2424
}
2525

26-
type vmContext struct{}
27-
28-
// Implement types.VMContext.
29-
func (*vmContext) OnVMStart(vmConfigurationSize int) types.OnVMStartStatus {
30-
return types.OnVMStartStatusOK
26+
type vmContext struct {
27+
// Embed the default VM context here,
28+
// so that we don't need to reimplement all the methods.
29+
types.DefaultVMContext
3130
}
3231

33-
// Implement types.VMContext.
32+
// Override types.DefaultVMContext.
3433
func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext {
3534
return &pluginContext{}
3635
}
3736

3837
type pluginContext struct {
39-
// Embed the default root context here,
38+
// Embed the default plugin context here,
4039
// so that we don't need to reimplement all the methods.
4140
types.DefaultPluginContext
4241
}
4342

44-
// Override DefaultPluginContext.
43+
// Override types.DefaultPluginContext.
4544
func (*pluginContext) NewHttpContext(contextID uint32) types.HttpContext {
4645
return &httpHeaders{contextID: contextID}
4746
}
@@ -53,7 +52,7 @@ type httpHeaders struct {
5352
contextID uint32
5453
}
5554

56-
// Override DefaultHttpContext.
55+
// Override types.DefaultHttpContext.
5756
func (ctx *httpHeaders) OnHttpRequestHeaders(numHeaders int, endOfStream bool) types.Action {
5857
err := proxywasm.ReplaceHttpRequestHeader("test", "best")
5958
if err != nil {
@@ -71,7 +70,7 @@ func (ctx *httpHeaders) OnHttpRequestHeaders(numHeaders int, endOfStream bool) t
7170
return types.ActionContinue
7271
}
7372

74-
// Override DefaultHttpContext.
73+
// Override types.DefaultHttpContext.
7574
func (ctx *httpHeaders) OnHttpResponseHeaders(numHeaders int, endOfStream bool) types.Action {
7675
hs, err := proxywasm.GetHttpResponseHeaders()
7776
if err != nil {
@@ -84,7 +83,7 @@ func (ctx *httpHeaders) OnHttpResponseHeaders(numHeaders int, endOfStream bool)
8483
return types.ActionContinue
8584
}
8685

87-
// Override DefaultHttpContext.
86+
// Override types.DefaultHttpContext.
8887
func (ctx *httpHeaders) OnHttpStreamDone() {
8988
proxywasm.LogInfof("%d finished", ctx.contextID)
9089
}

examples/http_routing/main.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,24 @@ func main() {
2626
proxywasm.SetVMContext(&vmContext{})
2727
}
2828

29-
type vmContext struct{}
30-
31-
// Implement types.VMContext.
32-
func (*vmContext) OnVMStart(vmConfigurationSize int) types.OnVMStartStatus {
33-
return types.OnVMStartStatusOK
29+
type vmContext struct {
30+
// Embed the default VM context here,
31+
// so that we don't need to reimplement all the methods.
32+
types.DefaultVMContext
3433
}
3534

36-
// Implement types.VMContext.
35+
// Override types.DefaultVMContext.
3736
func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext {
3837
return &pluginContext{}
3938
}
4039

4140
type pluginContext struct {
42-
// Embed the default root context here,
41+
// Embed the default plugin context here,
4342
// so that we don't need to reimplement all the methods.
4443
types.DefaultPluginContext
4544
}
4645

47-
// Override DefaultPluginContext.
46+
// Override types.DefaultPluginContext.
4847
func (*pluginContext) NewHttpContext(contextID uint32) types.HttpContext {
4948
return &httpRouting{}
5049
}
@@ -61,7 +60,7 @@ var now = func() int {
6160
return rand.Int()
6261
}
6362

64-
// Override DefaultHttpContext.
63+
// Override types.DefaultHttpContext.
6564
func (ctx *httpRouting) OnHttpRequestHeaders(numHeaders int, endOfStream bool) types.Action {
6665
// Randomly routing to the canary cluster.
6766
dice := now()

0 commit comments

Comments
 (0)