@@ -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 .
4039func (* vmContext ) NewPluginContext (contextID uint32 ) types.PluginContext {
4140 return & pluginContext {}
4241}
4342
4443type 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.
5251func (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.
6059func (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.
7877func (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.
104103func (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
133132type 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.
141140func (ctx * echoBodyContext ) OnHttpRequestBody (bodySize int , endOfStream bool ) types.Action {
142141 ctx .totalRequestBodySize += bodySize
143142 if ! endOfStream {
0 commit comments