You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+43-9Lines changed: 43 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,40 @@
1
1
# compute-sdk-go
2
2
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+).
4
4
5
5
## Quick Start
6
6
7
7
The Fastly Developer Hub has a great [Quick Start guide for Go](https://developer.fastly.com/learning/compute/go/).
8
8
9
9
Alternatively, you can take a look at the [Go Starter Kit](https://github.com/fastly/compute-starter-kit-go-default).
10
10
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:
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.
12
34
13
35
## Installation
14
36
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/).
16
38
17
39
Then, you can install `compute-sdk-go` in your project by running:
18
40
@@ -22,7 +44,7 @@ Then, you can install `compute-sdk-go` in your project by running:
22
44
23
45
Examples can be found in the [`examples`](./_examples) directory.
24
46
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.
26
48
27
49
## API Reference
28
50
@@ -32,20 +54,32 @@ The API reference documentation can be found on [pkg.go.dev/github.com/fastly/co
32
54
33
55
Tests that rely on a Compute@Edge runtime can utilize [Viceroy](https://github.com/fastly/Viceroy), our local development tool.
34
56
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.
36
60
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
38
62
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.)
40
64
41
-
Finally, run your tests:
65
+
To run your tests:
42
66
43
67
tinygo test -target=compute-at-edge.json ./...
44
68
45
69
You can try it out and make sure your local Viceroy environment is set up correctly by running the integration tests in this repository:
46
70
47
71
tinygo test -target=compute-at-edge.json ./integration_tests/...
48
72
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
+
49
83
## Logging
50
84
51
85
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
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/).
0 commit comments