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

Commit

Permalink
Update docs from github.com/stealthrocket/timecraft@989fa77435759849c…
Browse files Browse the repository at this point in the history
…50c5416f4f2adb0558f5c23
  • Loading branch information
stealthrocket-bot committed Aug 8, 2023
1 parent 3f9db5d commit c4eb408
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
48 changes: 29 additions & 19 deletions docs/applications/go.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
# Go

## Preparing Go
## Compiling your application

Go 1.21, due to be released in August 2023, will be able to natively compile Go applications to WebAssembly.
Since Go 1.21, you can natively compiled Go applications to WebAssembly using the wasip1 GOOS:

```bash
GOOS=wasip1 GOARCH=wasm go build ...
GOOS=wasip1 GOARCH=wasm go build -o app.wasm <path/to/main/pkg>
```

Since Go 1.21 has not been released yet, you can use [`gotip`](https://pkg.go.dev/golang.org/dl/gotip) to test these features before release:

```bash
go install golang.org/dl/gotip@latest
gotip download
```
If you prefer using TinyGo:

```bash
GOOS=wasip1 GOARCH=wasm gotip build ...
```

## Compiling your application

Instead of using `go build`, use:

```
GOOS=wasip1 GOARCH=wasm gotip build -o app.wasm <path/to/main/pkg>
tinygo build -o app.wasm -target=wasi <path/to/main/pkg>
```

This will build a WebAssembly module that can be run with Timecraft.
Expand All @@ -44,6 +31,10 @@ Timecraft from interpreting command-line options for the application, use:
timecraft run -- app.wasm arg1 arg2 ...
```

:::info
Note that `--` is optional but considered a best practice to separate runtime arguments and application arguments.
:::

Note that environment variables passed to Timecraft are automatically passed to the
WebAssembly module.

Expand All @@ -52,4 +43,23 @@ WebAssembly module.
You may quickly find that the networking capabilities of `GOOS=wasip1` are limited.

We have created a library to help with common use cases, such as creating HTTP servers
and connecting to databases. See https://github.com/stealthrocket/net for usage details.
and connecting to databases. See [github.com/stealthrocket/net](https://github.com/stealthrocket/net) for usage details.

Let's go over a quick example.


```go reference title="Simple HTTP server listening on http://localhost:3000"
https://github.com/stealthrocket/net/blob/main/examples/httpserver/main.go
```

In this example, we create a listener using WASI as well as the WasmEdge extension in order to serve incoming HTTP request through the WASI layer.

To build it and run it with the following commands:
```bash
GOOS=wasip1 GOARCH=wasm go build -o server.wasm main.go
timecraft run server.wasm
```

You should be able to use `curl` to query the server: `curl http://localhost:3000`

Check out the [github.com/stealthrocket/net](https://github.com/stealthrocket/net) to see more use cases.
2 changes: 1 addition & 1 deletion docs/guides/record-replay.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func main() {
```

```bash
$ GOOS=wasip1 GOARCH=wasm gotip build -o hello.wasm hello.go
$ GOOS=wasip1 GOARCH=wasm go build -o hello.wasm hello.go
$ timecraft run hello.wasm
7fdf35be-42e5-43ed-8417-8bc56e4cefd0
Hello, World!
Expand Down

0 comments on commit c4eb408

Please sign in to comment.