Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit 6f7d7d7

Browse files
committed
refactor: remove HostCall* prefix
Signed-off-by: mathetake <[email protected]>
1 parent d91a09b commit 6f7d7d7

File tree

11 files changed

+80
-82
lines changed

11 files changed

+80
-82
lines changed

examples/helloworld/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ func newHelloWorld(contextID uint32) proxywasm.RootContext {
3737
// override
3838
func (ctx *helloWorld) OnVMStart(int) bool {
3939
proxywasm.LogInfo("proxy_on_vm_start from Go!")
40-
if err := proxywasm.HostCallSetTickPeriodMilliSeconds(tickMilliseconds); err != nil {
40+
if err := proxywasm.SetTickPeriodMilliSeconds(tickMilliseconds); err != nil {
4141
proxywasm.LogCriticalf("failed to set tick period: %v", err)
4242
}
4343
return true
4444
}
4545

4646
// override
4747
func (ctx *helloWorld) OnTick() {
48-
t := proxywasm.HostCallGetCurrentTime()
48+
t := proxywasm.GetCurrentTime()
4949
proxywasm.LogInfof("OnTick on %d, it's %d", ctx.contextID, t)
5050
}

examples/http_auth_random/main.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func newContext(contextID uint32) proxywasm.HttpContext {
3939

4040
// override default
4141
func (ctx *httpAuthRandom) OnHttpRequestHeaders(int, bool) types.Action {
42-
hs, err := proxywasm.HostCallGetHttpRequestHeaders()
42+
hs, err := proxywasm.GetHttpRequestHeaders()
4343
if err != nil {
4444
proxywasm.LogCriticalf("failed to get request headers: %v", err)
4545
return types.ActionContinue
@@ -48,7 +48,7 @@ func (ctx *httpAuthRandom) OnHttpRequestHeaders(int, bool) types.Action {
4848
proxywasm.LogInfof("request header: %s: %s", h[0], h[1])
4949
}
5050

51-
if _, err := proxywasm.HostCallDispatchHttpCall(
51+
if _, err := proxywasm.DispatchHttpCall(
5252
clusterName, hs, "", [][2]string{}, 50000); err != nil {
5353
proxywasm.LogCriticalf("dipatch httpcall failed: %v", err)
5454
}
@@ -60,7 +60,7 @@ func (ctx *httpAuthRandom) OnHttpRequestHeaders(int, bool) types.Action {
6060

6161
// override default
6262
func (ctx *httpAuthRandom) OnHttpCallResponse(_ int, bodySize int, _ int) {
63-
hs, err := proxywasm.HostCallGetHttpCallResponseHeaders()
63+
hs, err := proxywasm.GetHttpCallResponseHeaders()
6464
if err != nil {
6565

6666
proxywasm.LogCriticalf("failed to get response body: %v", err)
@@ -71,29 +71,29 @@ func (ctx *httpAuthRandom) OnHttpCallResponse(_ int, bodySize int, _ int) {
7171
proxywasm.LogInfof("response header from %s: %s: %s", clusterName, h[0], h[1])
7272
}
7373

74-
b, err := proxywasm.HostCallGetHttpCallResponseBody(0, bodySize)
74+
b, err := proxywasm.GetHttpCallResponseBody(0, bodySize)
7575
if err != nil {
7676
proxywasm.LogCriticalf("failed to get response body: %v", err)
77-
proxywasm.HostCallResumeHttpRequest()
77+
proxywasm.ResumeHttpRequest()
7878
return
7979
}
8080

8181
s := fnv.New32a()
8282
if _, err := s.Write(b); err != nil {
8383
proxywasm.LogCriticalf("failed to calculate hash: %v", err)
84-
proxywasm.HostCallResumeHttpRequest()
84+
proxywasm.ResumeHttpRequest()
8585
return
8686
}
8787

8888
if s.Sum32()%2 == 0 {
8989
proxywasm.LogInfo("access granted")
90-
proxywasm.HostCallResumeHttpRequest()
90+
proxywasm.ResumeHttpRequest()
9191
return
9292
}
9393

9494
msg := "access forbidden"
9595
proxywasm.LogInfo(msg)
96-
proxywasm.HostCallSendHttpResponse(403, [][2]string{
96+
proxywasm.SendHttpResponse(403, [][2]string{
9797
{"powered-by", "proxy-wasm-go-sdk!!"},
9898
}, msg)
9999
}

examples/http_headers/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func newContext(contextID uint32) proxywasm.HttpContext {
3535

3636
// override
3737
func (ctx *httpHeaders) OnHttpRequestHeaders(int, bool) types.Action {
38-
hs, err := proxywasm.HostCallGetHttpRequestHeaders()
38+
hs, err := proxywasm.GetHttpRequestHeaders()
3939
if err != nil {
4040
proxywasm.LogCriticalf("failed to get request headers: %v", err)
4141
}
@@ -48,7 +48,7 @@ func (ctx *httpHeaders) OnHttpRequestHeaders(int, bool) types.Action {
4848

4949
// override
5050
func (ctx *httpHeaders) OnHttpResponseHeaders(int, bool) types.Action {
51-
hs, err := proxywasm.HostCallGetHttpResponseHeaders()
51+
hs, err := proxywasm.GetHttpResponseHeaders()
5252
if err != nil {
5353
proxywasm.LogCriticalf("failed to get request headers: %v", err)
5454
}

examples/network/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (ctx context) OnDownstreamData(dataSize int, _ bool) types.Action {
5050
return types.ActionContinue
5151
}
5252

53-
data, err := proxywasm.HostCallGetDownStreamData(0, dataSize)
53+
data, err := proxywasm.GetDownStreamData(0, dataSize)
5454
if err != nil && err != types.ErrorStatusNotFound {
5555
proxywasm.LogCritical(err.Error())
5656
}
@@ -69,14 +69,14 @@ func (ctx context) OnUpstreamData(dataSize int, _ bool) types.Action {
6969
return types.ActionContinue
7070
}
7171

72-
ret, err := proxywasm.HostCallGetProperty([]string{"upstream", "address"})
72+
ret, err := proxywasm.GetProperty([]string{"upstream", "address"})
7373
if err != nil {
7474
proxywasm.LogCritical(err.Error())
7575
}
7676

7777
proxywasm.LogInfof("remote address: %s", string(ret))
7878

79-
data, err := proxywasm.HostCallGetUpstreamData(0, dataSize)
79+
data, err := proxywasm.GetUpstreamData(0, dataSize)
8080
if err != nil && err != types.ErrorStatusNotFound {
8181
proxywasm.LogCritical(err.Error())
8282
}

examples/shared_data/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,22 @@ const sharedDataKey = "shared_data_key"
3030

3131
// override
3232
func (ctx data) OnVMStart(int) bool {
33-
if err := proxywasm.HostCallSetSharedData(sharedDataKey, []byte{0}, 0); err != nil {
33+
if err := proxywasm.SetSharedData(sharedDataKey, []byte{0}, 0); err != nil {
3434
proxywasm.LogWarnf("error setting shared data on OnVMStart: %v", err)
3535
}
3636
return true
3737
}
3838

3939
// override
4040
func (ctx data) OnHttpRequestHeaders(int, bool) types.Action {
41-
value, cas, err := proxywasm.HostCallGetSharedData(sharedDataKey)
41+
value, cas, err := proxywasm.GetSharedData(sharedDataKey)
4242
if err != nil {
4343
proxywasm.LogWarnf("error getting shared data on OnHttpRequestHeaders: %v", err)
4444
return types.ActionContinue
4545
}
4646

4747
value[0]++
48-
if err := proxywasm.HostCallSetSharedData(sharedDataKey, value, cas); err != nil {
48+
if err := proxywasm.SetSharedData(sharedDataKey, value, cas); err != nil {
4949
proxywasm.LogWarnf("error setting shared data on OnHttpRequestHeaders: %v", err)
5050
return types.ActionContinue
5151
}

examples/shared_queue/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ var queueID uint32
3535

3636
// override
3737
func (ctx queue) OnVMStart(int) bool {
38-
qID, err := proxywasm.HostCallRegisterSharedQueue(queueName)
38+
qID, err := proxywasm.RegisterSharedQueue(queueName)
3939
if err != nil {
4040
panic(err.Error())
4141
}
4242
queueID = qID
4343
proxywasm.LogInfof("queue registered, name: %s, id: %d", queueName, qID)
4444

45-
if err := proxywasm.HostCallSetTickPeriodMilliSeconds(tickMilliseconds); err != nil {
45+
if err := proxywasm.SetTickPeriodMilliSeconds(tickMilliseconds); err != nil {
4646
proxywasm.LogCriticalf("failed to set tick period: %v", err)
4747
}
4848
proxywasm.LogInfof("set tick period milliseconds: %d", tickMilliseconds)
@@ -52,7 +52,7 @@ func (ctx queue) OnVMStart(int) bool {
5252
// override
5353
func (ctx queue) OnHttpRequestHeaders(int, bool) types.Action {
5454
for _, msg := range []string{"hello", "world", "hello", "proxy-wasm"} {
55-
if err := proxywasm.HostCallEnqueueSharedQueue(queueID, []byte(msg)); err != nil {
55+
if err := proxywasm.EnqueueSharedQueue(queueID, []byte(msg)); err != nil {
5656
proxywasm.LogCriticalf("error queueing: %v", err)
5757
}
5858
}
@@ -61,7 +61,7 @@ func (ctx queue) OnHttpRequestHeaders(int, bool) types.Action {
6161

6262
// override
6363
func (ctx queue) OnTick() {
64-
data, err := proxywasm.HostCallDequeueSharedQueue(queueID)
64+
data, err := proxywasm.DequeueSharedQueue(queueID)
6565
switch err {
6666
case types.ErrorStatusEmpty:
6767
return

examples/vm_plugin_configuration/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type context struct{ proxywasm.DefaultContext }
2626

2727
// override
2828
func (ctx context) OnVMStart(vmConfigurationSize int) bool {
29-
data, err := proxywasm.HostCallGetVMConfiguration(vmConfigurationSize)
29+
data, err := proxywasm.GetVMConfiguration(vmConfigurationSize)
3030
if err != nil {
3131
proxywasm.LogCriticalf("error reading vm configuration: %v", err)
3232
}
@@ -36,7 +36,7 @@ func (ctx context) OnVMStart(vmConfigurationSize int) bool {
3636
}
3737

3838
func (ctx context) OnConfigure(pluginConfigurationSize int) bool {
39-
data, err := proxywasm.HostCallGetPluginConfiguration(pluginConfigurationSize)
39+
data, err := proxywasm.GetPluginConfiguration(pluginConfigurationSize)
4040
if err != nil {
4141
proxywasm.LogCriticalf("error reading plugin configuration: %v", err)
4242
}

proxywasm/abi_l7.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package proxywasm
1616

1717
import (
18+
"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/rawhostcall"
1819
"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types"
1920
)
2021

@@ -90,15 +91,15 @@ func proxyOnHttpCallResponse(_, calloutID uint32, numHeaders, bodySize, numTrail
9091

9192
if ctx, ok := currentState.streamContexts[ctxID]; ok {
9293
currentState.setActiveContextID(ctxID)
93-
hostCallSetEffectiveContext(ctxID)
94+
rawhostcall.ProxySetEffectiveContext(ctxID)
9495
ctx.OnHttpCallResponse(numHeaders, bodySize, numTrailers)
9596
} else if ctx, ok := currentState.httpContexts[ctxID]; ok {
9697
currentState.setActiveContextID(ctxID)
97-
hostCallSetEffectiveContext(ctxID)
98+
rawhostcall.ProxySetEffectiveContext(ctxID)
9899
ctx.OnHttpCallResponse(numHeaders, bodySize, numTrailers)
99100
} else if ctx, ok := currentState.rootContexts[ctxID]; ok {
100101
currentState.setActiveContextID(ctxID)
101-
hostCallSetEffectiveContext(ctxID)
102+
rawhostcall.ProxySetEffectiveContext(ctxID)
102103
ctx.OnHttpCallResponse(numHeaders, bodySize, numTrailers)
103104
} else {
104105
panic("invalid context on proxy_on_http_call_response")

proxywasm/abi_l7_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ package proxywasm
33
import (
44
"testing"
55

6-
"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/rawhostcall"
7-
86
"github.com/stretchr/testify/assert"
97
"github.com/stretchr/testify/require"
108

9+
"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/rawhostcall"
1110
"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types"
1211
)
1312

proxywasm/abi_queue.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package proxywasm
1616

17+
import "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/rawhostcall"
18+
1719
//export proxy_on_queue_ready
1820
func proxyOnQueueReady(contextID, queueID uint32) {
1921
ctx, ok := currentState.rootContexts[contextID]
@@ -22,6 +24,6 @@ func proxyOnQueueReady(contextID, queueID uint32) {
2224
}
2325

2426
currentState.setActiveContextID(contextID)
25-
hostCallSetEffectiveContext(contextID)
27+
rawhostcall.ProxySetEffectiveContext(contextID)
2628
ctx.OnQueueReady(queueID)
2729
}

0 commit comments

Comments
 (0)