diff --git a/content/spin/v2/go-components.md b/content/spin/v2/go-components.md index 4c853d56d..d4eaf7bf2 100644 --- a/content/spin/v2/go-components.md +++ b/content/spin/v2/go-components.md @@ -30,9 +30,7 @@ Using TinyGo to compile components for Spin is currently required, as the ## Versions -TinyGo `0.29.0` is recommended, which requires Go `v1.18+` or newer. - -> TinyGo version `0.29.0` is known to have issues with Spin on some systems. +TinyGo `0.30.0` is recommended, which requires Go `v1.19+`. ## HTTP Components @@ -67,6 +65,35 @@ func init() { func main() {} ``` +The Spin HTTP component (written in Go) can be built using the `tingygo` toolchain: + + + +```bash +$ tinygo build -o main.wasm -target=wasi main.go +``` + +Once built, we can run our Spin HTTP component using the Spin up command: + + + +```bash +$ spin up +``` + +The Spin HTTP component can now receive and process incoming requests: + + + +```bash +$ curl -i localhost:3000 +HTTP/1.1 200 OK +content-type: text/plain +content-length: 15 + +Hello Fermyon! +``` + The important things to note in the implementation above: - the entry point to the component is the standard `func init()` for Go programs @@ -118,12 +145,12 @@ func init() { func main() {} ``` -The component can be built using the `tingygo` toolchain: +The Outbound HTTP Request example above can be built using the `tingygo` toolchain: ```bash -$ tinygo build -wasm-abi=generic -target=wasi -no-debug -o main.wasm main.go +$ tinygo build -o main.wasm -target=wasi main.go ``` Before we can execute this component, we need to add the @@ -159,10 +186,7 @@ now receive requests in route `/hello`: ```bash $ curl -i localhost:3000/hello HTTP/1.1 200 OK -content-type: text/plain; charset=utf-8 -server: spin/0.1.0 -content-length: 85 -date = "2023-11-04T00:00:01Z" +content-length: 93 {"timestamp":1684299253331,"fact":"Reindeer grow new antlers every year"} ``` @@ -231,7 +255,7 @@ component = "echo-message" [component.echo-message] source = "main.wasm" [component.echo-message.build] -command = "tinygo build -wasm-abi=generic -target=wasi -gc=leaking -no-debug -o main.wasm main.go" +command = "tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go" ``` The application will connect to `redis://localhost:6379`, and for every new message @@ -364,4 +388,4 @@ For more information about using SQLite from TinyGo, see [SQLite storage](sqlite ## AI Inferencing From Go Components -For more information about using Serverless AI from TinyGo, see the [Serverless AI](serverless-ai-api-guide) API guide. \ No newline at end of file +For more information about using Serverless AI from TinyGo, see the [Serverless AI](serverless-ai-api-guide) API guide.