Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

convert status codes to Go errors #19

Merged
merged 1 commit into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion examples/helloworld/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ func newHelloWorld(contextID uint32) runtime.RootContext {
// override
func (ctx *helloWorld) OnVMStart(_ int) bool {
runtime.LogInfo("proxy_on_vm_start from Go!")
ctx.SetTickPeriod(1000)
if err := ctx.SetTickPeriod(1000); err != nil {
runtime.LogCritical("failed to set tick period: " + err.Error())
}
return true
}

Expand Down
17 changes: 10 additions & 7 deletions examples/http_auth_random/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,27 @@ func newContext(contextID uint32) runtime.HttpContext {

// override default
func (ctx *httpHeaders) OnHttpRequestHeaders(_ int, _ bool) types.Action {
hs, st := ctx.GetHttpRequestHeaders()
if st != types.StatusOk {
runtime.LogCritical("failed to get request headers")
hs, err := ctx.GetHttpRequestHeaders()
if err != nil {
runtime.LogCritical("failed to get request headers: " + err.Error())
return types.ActionContinue
}
for _, h := range hs {
runtime.LogInfo("request header: " + h[0] + ": " + h[1])
}

ctx.DispatchHttpCall("httpbin", hs, "", [][2]string{}, 50000)
if _, err := ctx.DispatchHttpCall(
"httpbin", hs, "", [][2]string{}, 50000); err != nil {
runtime.LogCritical("dipatch httpcall failed: " + err.Error())
}
return types.ActionPause
}

// override default
func (ctx *httpHeaders) OnHttpCallResponse(_ uint32, _ int, bodySize int, _ int) {
b, st := ctx.GetHttpCallResponseBody(0, bodySize)
if st != types.StatusOk {
runtime.LogCritical("failed to get response body")
b, err := ctx.GetHttpCallResponseBody(0, bodySize)
if err != nil {
runtime.LogCritical("failed to get response body: " + err.Error())
ctx.ResumeHttpRequest()
return
}
Expand Down
12 changes: 6 additions & 6 deletions examples/http_headers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ func newContext(contextID uint32) runtime.HttpContext {

// override
func (ctx *httpHeaders) OnHttpRequestHeaders(_ int, _ bool) types.Action {
hs, st := ctx.GetHttpRequestHeaders()
if st != types.StatusOk {
runtime.LogCritical("failed to get request headers")
hs, err := ctx.GetHttpRequestHeaders()
if err != nil {
runtime.LogCritical("failed to get request headers: " + err.Error())
}

for _, h := range hs {
Expand All @@ -36,9 +36,9 @@ func (ctx *httpHeaders) OnHttpRequestHeaders(_ int, _ bool) types.Action {

// override
func (ctx *httpHeaders) OnHttpResponseHeaders(_ int, _ bool) types.Action {
hs, st := ctx.GetHttpResponseHeaders()
if st != types.StatusOk {
runtime.LogCritical("failed to get request headers")
hs, err := ctx.GetHttpResponseHeaders()
if err != nil {
runtime.LogCritical("failed to get request headers: " + err.Error())
}

for _, h := range hs {
Expand Down
Loading