Skip to content

Commit

Permalink
feat(go-examples): allow compilation with tinygo 0.33
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Volosatovs <[email protected]>
  • Loading branch information
rvolosatovs committed Sep 25, 2024
1 parent 09a05c7 commit d3bcc3b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 13 deletions.
13 changes: 1 addition & 12 deletions examples/go/http/http.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//go:generate go run github.com/bytecodealliance/wasm-tools-go/cmd/wit-bindgen-go generate -w app -o bindings ./wit

package app
package main

import (
"log/slog"
"unsafe"

"github.com/bytecodealliance/wasm-tools-go/cm"
Expand All @@ -24,40 +23,30 @@ func ptr[T any](v T) *T {
}

func handle(req types.IncomingRequest, out types.ResponseOutparam) *types.ErrorCode {
slog.Debug("constructing new response")
resp := types.NewOutgoingResponse(req.Headers())

slog.Debug("getting response body")
body := resp.Body()
if body.IsErr() {
slog.Debug("failed to get response body")
return ptr(types.ErrorCodeInternalError(cm.Some("failed to get response body")))
}
bodyOut := body.OK()

slog.Debug("getting response body stream")
bodyWrite := bodyOut.Write()
if bodyWrite.IsErr() {
slog.Debug("failed to get response body stream")
return ptr(types.ErrorCodeInternalError(cm.Some("failed to get response body stream")))
}

slog.Debug("setting response outparam")
types.ResponseOutparamSet(out, cm.OK[cm.Result[types.ErrorCodeShape, types.OutgoingResponse, types.ErrorCode]](resp))
stream := bodyWrite.OK()
s := "hello world"
writeRes := stream.BlockingWriteAndFlush(cm.NewList(unsafe.StringData(s), uint(len(s))))
if writeRes.IsErr() {
slog.Error("failed to write to stream", "err", writeRes.Err())
return nil
}
slog.Debug("dropping body stream")
stream.ResourceDrop()

slog.Debug("finishing outgoing body")
finishRes := types.OutgoingBodyFinish(*bodyOut, cm.None[types.Fields]())
if finishRes.IsErr() {
slog.Error("failed to finish outgoing body", "err", finishRes.Err())
return nil
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion examples/go/http/http_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:generate go run github.com/wasmCloud/wadge/cmd/wadge-bindgen-go

package app_test
package main_test

import (
"io"
Expand Down

0 comments on commit d3bcc3b

Please sign in to comment.