From 8f82d29e65d8096489a2bdee540fd93d113a85bb Mon Sep 17 00:00:00 2001 From: Timothy McCallum Date: Mon, 8 Jan 2024 11:24:12 +1000 Subject: [PATCH 1/4] Update Go Components page - to align with 2.1.0 Signed-off-by: tpmccallum tim.mccallum@fermyon.com Signed-off-by: Timothy McCallum --- content/spin/v2/go-components.md | 48 ++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/content/spin/v2/go-components.md b/content/spin/v2/go-components.md index 4c853d56d..0a1c88f72 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 (written in Go) using the Spin up command: + + + +```bash +$ spin up +``` + +The Spin HTTP component (written in Go) 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 @@ -157,12 +184,9 @@ now receive requests in route `/hello`: ```bash -$ curl -i localhost:3000/hello +$ curl -i localhost:3000 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. From ccbe1f3057e2962831d2da89e75e952b283cb5af Mon Sep 17 00:00:00 2001 From: Timothy McCallum Date: Mon, 8 Jan 2024 12:02:42 +1000 Subject: [PATCH 2/4] Adjust curl command for correct endpoint Signed-off-by: tpmccallum tim.mccallum@fermyon.com Signed-off-by: Timothy McCallum --- content/spin/v2/go-components.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/spin/v2/go-components.md b/content/spin/v2/go-components.md index 0a1c88f72..eb6a5b773 100644 --- a/content/spin/v2/go-components.md +++ b/content/spin/v2/go-components.md @@ -184,7 +184,7 @@ now receive requests in route `/hello`: ```bash -$ curl -i localhost:3000 +$ curl -i localhost:3000/hello HTTP/1.1 200 OK content-length: 93 From 22bc2e5b0659044c7a7856c399bff575e9e50016 Mon Sep 17 00:00:00 2001 From: Timothy McCallum Date: Mon, 8 Jan 2024 15:24:56 +1000 Subject: [PATCH 3/4] Update content/spin/v2/go-components.md Signed-off-by: tpmccallum tim.mccallum@fermyon.com Co-authored-by: itowlson Signed-off-by: Timothy McCallum --- content/spin/v2/go-components.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/spin/v2/go-components.md b/content/spin/v2/go-components.md index eb6a5b773..1d7801eb5 100644 --- a/content/spin/v2/go-components.md +++ b/content/spin/v2/go-components.md @@ -73,7 +73,7 @@ The Spin HTTP component (written in Go) can be built using the `tingygo` toolcha $ tinygo build -o main.wasm -target=wasi main.go ``` -Once built, we can run our Spin HTTP component (written in Go) using the Spin up command: +Once built, we can run our Spin HTTP component using the Spin up command: From 35d993520d1e753b5459c3ed45380c3c369d7cc1 Mon Sep 17 00:00:00 2001 From: Timothy McCallum Date: Mon, 8 Jan 2024 15:25:11 +1000 Subject: [PATCH 4/4] Update content/spin/v2/go-components.md Signed-off-by: tpmccallum tim.mccallum@fermyon.com Co-authored-by: itowlson Signed-off-by: Timothy McCallum --- content/spin/v2/go-components.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/spin/v2/go-components.md b/content/spin/v2/go-components.md index 1d7801eb5..d4eaf7bf2 100644 --- a/content/spin/v2/go-components.md +++ b/content/spin/v2/go-components.md @@ -81,7 +81,7 @@ Once built, we can run our Spin HTTP component using the Spin up command: $ spin up ``` -The Spin HTTP component (written in Go) can now receive and process incoming requests: +The Spin HTTP component can now receive and process incoming requests: