Skip to content

Commit 454f9b8

Browse files
committed
Update Go docs for v4
Signed-off-by: itowlson <ivan.towlson@fermyon.com>
1 parent 34e4ddc commit 454f9b8

16 files changed

Lines changed: 86 additions & 104 deletions

content/v4/build.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,15 @@ command = "componentize-py -w spin-http componentize app -o app.wasm"
122122

123123
{{ blockEnd }}
124124

125-
{{ startTab "TinyGo" }}
125+
{{ startTab "Go" }}
126126

127-
For Go applications, you must use the TinyGo compiler, as the standard Go compiler does not yet support the WASI standard. See the [TinyGo installation guide](https://tinygo.org/getting-started/install/).
128-
129-
The build command calls TinyGo with the WASI backend and appropriate options:
127+
The build command calls `go tool` to run the `componentize-go` tool with appropriate options:
130128

131129
<!-- @nocpy -->
132130

133131
```toml
134132
[component.hello.build]
135-
command = "tinygo build -target=wasip1 -gc=leaking -buildmode=c-shared -no-debug -o main.wasm ."
133+
command = "go tool componentize-go build"
136134
```
137135

138136
{{ blockEnd }}

content/v4/contributing-docs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ test.sh
216216
- `macOS`
217217
- `Python`
218218
- `Rust`
219-
- `TinyGo`
219+
- `Go`
220220
- `TypeScript`
221221
- `v0.9.0`
222222
- `v0.10.0`

content/v4/go-components.md

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,21 @@ url = "https://github.com/spinframework/spin-docs/blob/main/content/v4/go-compon
1414
- [Spawning Asynchronous Tasks](#spawning-asynchronous-tasks)
1515
- [Creating Futures and Streams](#creating-futures-and-streams)
1616
- [Storing Data in Redis From Go Components](#storing-data-in-redis-from-go-components)
17-
- [Using Go Packages in Spin Components](#using-go-packages-in-spin-components)
1817
- [Storing Data in the Spin Key-Value Store](#storing-data-in-the-spin-key-value-store)
1918
- [Storing Data in SQLite](#storing-data-in-sqlite)
2019
- [AI Inferencing From Go Components](#ai-inferencing-from-go-components)
2120

2221
> This guide assumes you have Spin installed. If this is your first encounter with Spin, please see the [Quick Start](quickstart), which includes information about installing Spin with the Go templates, installing required tools, and creating Go applications.
2322
24-
> This guide assumes you are familiar with the Go programming language, and that
25-
> you have
26-
> [configured the TinyGo toolchain locally](https://tinygo.org/getting-started/install/).
27-
Using TinyGo to compile components for Spin is currently required, as the
28-
[Go compiler doesn't currently have support for compiling to WASI](https://github.com/golang/go/issues/31105).
23+
> This guide assumes you are familiar with the Go programming language.
2924
3025
> All examples from this page can be found in [the Spin Go SDK repository on GitHub](https://github.com/spinframework/spin-go-sdk/tree/main/examples).
3126
32-
[**Want to go straight to the Spin SDK reference documentation?** Find it here.](https://pkg.go.dev/github.com/spinframework/spin-go-sdk/v2)
27+
[**Want to go straight to the Spin SDK reference documentation?** Find it here.](https://pkg.go.dev/github.com/spinframework/spin-go-sdk/v3)
3328

3429
## Versions
3530

36-
TinyGo `0.35.0` is recommended, which requires Go `v1.22+`. Older versions of TinyGo may not support the command-line flags used when building Spin applications.
31+
You will need Go 1.25.5 or above.
3732

3833
## HTTP Components
3934

@@ -152,7 +147,7 @@ import (
152147
"net/http"
153148
"os"
154149

155-
spinhttp "github.com/spinframework/spin-go-sdk/v2/http"
150+
spinhttp "github.com/spinframework/spin-go-sdk/v3/http"
156151
)
157152

158153
func init() {
@@ -164,19 +159,19 @@ func init() {
164159

165160
// `spin.toml` is not configured to allow outbound HTTP requests to this host,
166161
// so this request will fail.
167-
if _, err := spinhttp.Get("https://fermyon.com"); err != nil {
162+
if _, err := spinhttp.Get("https://forbidden.com"); err != nil {
168163
fmt.Fprintf(os.Stderr, "Cannot send HTTP request: %v", err)
169164
}
170165
})
171166
}
172167
```
173168

174-
The Outbound HTTP Request example above can be built using the `tingygo` toolchain:
169+
The Outbound HTTP Request example above can be built using `go tool componentize-go build`:
175170

176171
<!-- @selectiveCpy -->
177172

178173
```bash
179-
$ tinygo build -target=wasip1 -gc=leaking -buildmode=c-shared -no-debug -o main.wasm .
174+
$ go tool componentize-go build
180175
```
181176

182177
Before we can execute this component, we need to add the
@@ -191,14 +186,14 @@ requests to:
191186
spin_manifest_version = 2
192187

193188
[application]
194-
name = "spin-hello-tinygo"
189+
name = "spin-hello-go"
195190
version = "1.0.0"
196191

197192
[[trigger.http]]
198193
route = "/hello"
199-
component = "tinygo-hello"
194+
component = "go-hello"
200195

201-
[component.tinygo-hello]
196+
[component.go-hello]
202197
source = "main.wasm"
203198
allowed_outbound_hosts = [ "https://random-data-api.fermyon.app" ]
204199
```
@@ -243,7 +238,7 @@ package main
243238
import (
244239
"fmt"
245240

246-
"github.com/spinframework/spin-go-sdk/v2/redis"
241+
"github.com/spinframework/spin-go-sdk/v3/redis"
247242
)
248243

249244
func init() {
@@ -278,7 +273,7 @@ component = "echo-message"
278273
[component.echo-message]
279274
source = "main.wasm"
280275
[component.echo-message.build]
281-
command = "tinygo build -target=wasip1 -gc=leaking -buildmode=c-shared -no-debug -o main.wasm ."
276+
command = "go tool componentize-go build"
282277
```
283278

284279
The application will connect to `redis://localhost:6379`, and for every new message
@@ -348,8 +343,8 @@ import (
348343
"net/http"
349344
"os"
350345

351-
spin_http "github.com/spinframework/spin-go-sdk/v2/http"
352-
"github.com/spinframework/spin-go-sdk/v2/redis"
346+
spin_http "github.com/spinframework/spin-go-sdk/v3/http"
347+
"github.com/spinframework/spin-go-sdk/v3/redis"
353348
)
354349

355350
func init() {
@@ -365,7 +360,7 @@ func init() {
365360
channel := os.Getenv("REDIS_CHANNEL")
366361

367362
// payload is the data publish to the redis channel.
368-
payload := []byte(`Hello redis from tinygo!`)
363+
payload := []byte(`Hello redis from Go!`)
369364

370365
// create a new redis client.
371366
rdb := redis.NewClient(addr)
@@ -407,22 +402,14 @@ This HTTP component can be paired with a Redis component, triggered on new messa
407402
> You can find a complete example for using outbound Redis from an HTTP component
408403
> in the [Spin repository on GitHub](https://github.com/spinframework/spin-go-sdk/tree/main/examples/redis-outbound).
409404
410-
## Using Go Packages in Spin Components
411-
412-
Any [package from the Go standard library](https://tinygo.org/docs/reference/lang-support/stdlib/) that can be imported in TinyGo and that compiles to
413-
WASI can be used when implementing a Spin component.
414-
415-
> Make sure to read [the page describing the HTTP trigger](./http-trigger.md) for more
416-
> details about building HTTP applications.
417-
418405
## Storing Data in the Spin Key-Value Store
419406

420-
Spin has a key-value store built in. For information about using it from TinyGo, see [the key-value API guide](kv-store-api-guide).
407+
Spin has a key-value store built in. For information about using it from Go, see [the key-value API guide](kv-store-api-guide).
421408

422409
## Storing Data in SQLite
423410

424-
For more information about using SQLite from TinyGo, see [SQLite storage](sqlite-api-guide).
411+
For more information about using SQLite from Go, see [SQLite storage](sqlite-api-guide).
425412

426413
## AI Inferencing From Go Components
427414

428-
For more information about using Serverless AI from TinyGo, see the [Serverless AI](serverless-ai-api-guide) API guide.
415+
For more information about using Serverless AI from Go, see the [Serverless AI](serverless-ai-api-guide) API guide.

content/v4/http-outbound.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,15 @@ You can find a complete example for using outbound HTTP in the [Python SDK repos
201201

202202
{{ blockEnd }}
203203

204-
{{ startTab "TinyGo"}}
204+
{{ startTab "Go"}}
205205

206-
> [**Want to go straight to the reference documentation?** Find it here.](https://pkg.go.dev/github.com/spinframework/spin-go-sdk/v2@v2.2.1/http)
206+
> [**Want to go straight to the reference documentation?** Find it here.](https://pkg.go.dev/github.com/spinframework/spin-go-sdk/v3@v3.0.0/http)
207207
208-
HTTP functions are available in the `github.com/spinframework/spin-go-sdk/v2/http` package. [See Go Packages for reference documentation.](https://pkg.go.dev/github.com/spinframework/spin-go-sdk/v2/http) The general function is named `Send`, but the Go SDK also surfaces individual functions, with request-specific parameters, for the `Get` and `Post` operations. For example:
208+
HTTP functions are available in the `github.com/spinframework/spin-go-sdk/v3/http` package. [See Go Packages for reference documentation.](https://pkg.go.dev/github.com/spinframework/spin-go-sdk/v3/http) The general function is named `Send`, but the Go SDK also surfaces individual functions, with request-specific parameters, for the `Get` and `Post` operations. For example:
209209

210210
```go
211211
import (
212-
spinhttp "github.com/spinframework/spin-go-sdk/v2/http"
212+
spinhttp "github.com/spinframework/spin-go-sdk/v3/http"
213213
)
214214

215215
res1, err1 := spinhttp.Get("https://random-data-api.fermyon.app/animals/json")
@@ -218,13 +218,13 @@ res2, err2 := spinhttp.Post("https://example.com/users", "application/json", jso
218218
request, err := http.NewRequest("PUT", "https://example.com/users/1", bytes.NewBufferString(user1))
219219
request.Header.Add("content-type", "application/json")
220220
res3, err3 := spinhttp.Send(req)
221-
222221
```
223222

224223
**Notes**
225224

226225
* In the `Post` function, the body is an `io.Reader`. The Spin SDK reads this into the underlying Wasm byte array.
227226
* The `NewRequest` function is part of the standard library. The `Send` method adapts the standard request type to the underlying Wasm interface.
227+
* The response has a `Body` field of type `io.Reader`.
228228
* Errors are returned through the usual Go multiple return values mechanism.
229229

230230
You can find a complete example for using outbound HTTP in the [Spin repository on GitHub](https://github.com/spinframework/spin-go-sdk/tree/main/examples/http-outbound).

content/v4/http-trigger.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ Other paths within the reserved space currently return 404 Not Found.
143143

144144
## Authoring HTTP Components
145145

146-
> Spin has two ways of running HTTP components, depending on language support for the evolving WebAssembly component standards. This section describes the default way, which is currently used by Rust, JavaScript/TypeScript, Python, and TinyGo components. For other languages, see [HTTP Components with Wagi](#http-with-wagi-webassembly-gateway-interface) below.
146+
> Spin has two ways of running HTTP components, depending on language support for the evolving WebAssembly component standards. This section describes the default way, which is currently used by Rust, JavaScript/TypeScript, Python, and Go components. For other languages, see [HTTP Components with Wagi](#http-with-wagi-webassembly-gateway-interface) below.
147147
148148
By default, Spin runs components using the [WebAssembly component model](https://component-model.bytecodealliance.org/). In this model, the Wasm module exports a well-known interface that Spin calls to handle the HTTP request.
149149

@@ -247,9 +247,9 @@ You can find a complete example for handling a HTTP request in the [Python SDK r
247247

248248
{{ blockEnd }}
249249

250-
{{ startTab "TinyGo"}}
250+
{{ startTab "Go"}}
251251

252-
> [**Want to go straight to the reference documentation?** Find it here.](https://pkg.go.dev/github.com/spinframework/spin-go-sdk/v2@v2.2.1/http)
252+
> [**Want to go straight to the reference documentation?** Find it here.](https://pkg.go.dev/github.com/spinframework/spin-go-sdk/v3@v3.0.0/http)
253253
254254
In Go, you register the handler as a callback in your program's `init` function. Set `handler.Exports.Handle` to your handler function. Your handler takes a `*Request` pointer, and returns a `Result[Response, ErrorCode]` with the response.
255255

content/v4/kv-store-api-guide.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,21 +176,20 @@ You can find a complete Python code example using the Key Value store in the [Sp
176176

177177
{{ blockEnd }}
178178

179-
{{ startTab "TinyGo"}}
179+
{{ startTab "Go"}}
180180

181-
> [**Want to go straight to the Spin SDK reference documentation?** Find it here.](https://pkg.go.dev/github.com/spinframework/spin-go-sdk/v2@v2.2.1/kv)
181+
> [**Want to go straight to the Spin SDK reference documentation?** Find it here.](https://pkg.go.dev/github.com/spinframework/spin-go-sdk/v3@v3.0.0/kv)
182182
183-
Key value functions are provided by the `github.com/spinframework/spin-go-sdk/v2/kv` module. [See Go Packages for reference documentation.](https://pkg.go.dev/github.com/spinframework/spin-go-sdk/v2/kv) For example:
183+
Key value functions are provided by the `github.com/spinframework/spin-go-sdk/v3/kv` module. [See Go Packages for reference documentation.](https://pkg.go.dev/github.com/spinframework/spin-go-sdk/v3/kv) For example:
184184

185185
```go
186-
import "github.com/spinframework/spin-go-sdk/v2/kv"
186+
import "github.com/spinframework/spin-go-sdk/v3/kv"
187187

188188
func example() error {
189189
store, err := kv.OpenStore("default")
190190
if err != nil {
191191
return err
192192
}
193-
defer store.Close()
194193
previous, err := store.Get("mykey")
195194
return store.Set("mykey", []byte("myvalue"))
196195
}

content/v4/language-support-overview.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ This page contains information about language support for Spin features:
8383

8484
{{ blockEnd }}
8585

86-
{{ startTab "TinyGo"}}
86+
{{ startTab "Go"}}
8787

88-
**[📄 Visit the TinyGo Spin SDK reference documentation](https://pkg.go.dev/github.com/spinframework/spin-go-sdk/v2) to see specific modules, functions, variables and syntax relating to the following TinyGo SDK.**
88+
**[📄 Visit the Go Spin SDK reference documentation](https://pkg.go.dev/github.com/spinframework/spin-go-sdk/v3) to see specific modules, functions, variables and syntax relating to the following Go SDK.**
8989

9090
| Feature | SDK Supported? |
9191
|-----|-----|

content/v4/mqtt-outbound.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ You can find a complete Python code example for using outbound MQTT from an HTTP
103103

104104
{{ blockEnd }}
105105

106-
{{ startTab "TinyGo"}}
106+
{{ startTab "Go"}}
107107

108108
MQTT is not available in the current version of the Go SDK.
109109

0 commit comments

Comments
 (0)