Skip to content

Commit 7fdf180

Browse files
authored
Merge pull request #77 from fastly/dgryski/go-1.21-readme
README: update for Go 1.21 release
2 parents 08c2b97 + b3e09f8 commit 7fdf180

File tree

1 file changed

+43
-9
lines changed

1 file changed

+43
-9
lines changed

README.md

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,40 @@
11
# compute-sdk-go
22

3-
Experimental Go SDK for building [Compute@Edge](https://www.fastly.com/products/edge-compute/serverless) applications with [TinyGo](https://tinygo.org/).
3+
Experimental Go SDK for building [Compute@Edge](https://www.fastly.com/products/edge-compute/serverless) applications with [Go](https://go.dev) (1.21+) and [TinyGo](https://tinygo.org/) (0.28.1+).
44

55
## Quick Start
66

77
The Fastly Developer Hub has a great [Quick Start guide for Go](https://developer.fastly.com/learning/compute/go/).
88

99
Alternatively, you can take a look at the [Go Starter Kit](https://github.com/fastly/compute-starter-kit-go-default).
1010

11-
You'll also want to take a look at our [Recommended Packages](#recommended-packages) section, as this can help with the sharp edges of the SDK, like JSON support.
11+
If you're using TinyGo, you'll also want to take a look at our [TinyGo Recommended Packages](#tinygo-recommended-packages) section, as this can help with the sharp edges of the SDK, like JSON support.
12+
13+
## Supported Toolchains
14+
15+
Compute@Edge builds on top of WebAssembly and the [WebAssembly System Interface](https://wasi.dev/).
16+
17+
TinyGo supports WASI as a target, and Go does as of its 1.21 release.
18+
19+
Each toolchain has its own tradeoffs. Generally speaking, TinyGo produces smaller compiled artifacts and takes less RAM at runtime. Build times are generally longer, sometimes considerably. TinyGo does not support all of the Go standard library, and in particular support for the `reflect` package is incomplete. This means that some third-party packages may not work with TinyGo.
20+
21+
Runtime performance is mixed, with TinyGo faster on some applications and Go faster on others. If you have a performance-critical application, we recommend benchmarking both toolchains to see which works best for you.
22+
23+
To switch between TinyGo and Go, set the `build` command in the `[scripts]` section of your `fastly.toml` as follows:
24+
25+
[scripts]
26+
build = "tinygo build -target=wasi -o bin/main.wasm ."
27+
28+
or
29+
30+
[scripts]
31+
build = "GOARCH=wasm GOOS=wasip1 go build -o bin/main.wasm ."
32+
33+
You might need to adjust the actual build command depending on your project.
1234

1335
## Installation
1436

15-
First, install TinyGo by following the [TinyGo Quick install guide](https://tinygo.org/getting-started/install/).
37+
If you're using Go, download [the latest Go release](https://go.dev/dl/). For TinyGo, follow the [TinyGo Quick install guide](https://tinygo.org/getting-started/install/).
1638

1739
Then, you can install `compute-sdk-go` in your project by running:
1840

@@ -22,7 +44,7 @@ Then, you can install `compute-sdk-go` in your project by running:
2244

2345
Examples can be found in the [`examples`](./_examples) directory.
2446

25-
The Fastly Developer Hub has a collection of [common use cases in VCL ported to TinyGo](https://developer.fastly.com/learning/compute/migrate/) which also acts as a great set of introductory examples of using TinyGo on Compute@Edge.
47+
The Fastly Developer Hub has a collection of [common use cases in VCL ported to Go](https://developer.fastly.com/learning/compute/migrate/) which also acts as a great set of introductory examples of using Go on Compute@Edge.
2648

2749
## API Reference
2850

@@ -32,20 +54,32 @@ The API reference documentation can be found on [pkg.go.dev/github.com/fastly/co
3254

3355
Tests that rely on a Compute@Edge runtime can utilize [Viceroy](https://github.com/fastly/Viceroy), our local development tool.
3456

35-
First, you'll need to install Viceroy and ensure the `viceroy` command is available in your path.
57+
Install Viceroy and ensure the `viceroy` command is available in your path.
58+
59+
Write your tests as ordinary Go tests. Viceroy provides the Compute@Edge APIs locally, although be aware that not all platform functionality is available. You can look at the `integration_tests` directory for examples.
3660

37-
Next, you'll need to create a TinyGo target that knows to run Viceroy. You can copy the `compute-at-edge.json` file from this repository for this purpose. (In the future, we will include this in the Go starter kits.)
61+
### TinyGo
3862

39-
Write your tests as ordinary Go tests. You can use Compute@Edge APIs in your tests, although be aware that not all platform functionality is available in Viceroy. You can look at the `integration_tests` directory for examples.
63+
The `compute-at-edge.json` file provides a TinyGo target to run Viceroy. (In the future, we will include this in the Go starter kits.)
4064

41-
Finally, run your tests:
65+
To run your tests:
4266

4367
tinygo test -target=compute-at-edge.json ./...
4468

4569
You can try it out and make sure your local Viceroy environment is set up correctly by running the integration tests in this repository:
4670

4771
tinygo test -target=compute-at-edge.json ./integration_tests/...
4872

73+
### Go
74+
75+
To run tests with Viceroy and Go
76+
77+
GOARCH=wasm GOOS=wasip1 go test -exec "viceroy run -C fastly.toml" -v ./...
78+
79+
You can try it out and make sure your local Viceroy environment is set up correctly by running the integration tests in this repository:
80+
81+
GOARCH=wasm GOOS=wasip1 go test -exec "viceroy run -C fastly.toml" -v ./integration_tests/...
82+
4983
## Logging
5084

5185
Logging can be done using a Fastly Compute@Edge Log Endpoint ([example](./_examples/logging-and-env/main.go)), or by using normal stdout like:
@@ -54,7 +88,7 @@ Logging can be done using a Fastly Compute@Edge Log Endpoint ([example](./_examp
5488
fmt.Printf("request received: %s\n", r.URL.String())
5589
```
5690

57-
## Recommended Packages
91+
## TinyGo Recommended Packages
5892

5993
TinyGo is still a new project, which has yet to get a version `1.0.0`. Therefore, the project is incomplete, but in its current state can still handle a lot of tasks on Compute@Edge. However, [some languages features of Go are still missing](https://tinygo.org/docs/reference/lang-support/).
6094

0 commit comments

Comments
 (0)