Skip to content

Commit a9a9ada

Browse files
authored
Merge pull request spinframework#921 from etehtsea/upd-examples
chore: Update examples
2 parents 4f22512 + 0f8c025 commit a9a9ada

File tree

12 files changed

+99
-144
lines changed

12 files changed

+99
-144
lines changed

examples/config-tinygo/Makefile

Lines changed: 0 additions & 7 deletions
This file was deleted.

examples/config-tinygo/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Spin component in TinyGo
2+
3+
```shell
4+
$ RUST_LOG=spin=trace spin build --up
5+
```
6+
7+
The application can now receive requests on `http://localhost:3000`:
8+
9+
```shell
10+
$ curl -i localhost:3000
11+
HTTP/1.1 200 OK
12+
content-length: 23
13+
date: Tue, 29 Nov 2022 06:59:24 GMT
14+
15+
message: I'm a teapot
16+
```

examples/config-tinygo/spin.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ source = "main.wasm"
1414
[component.trigger]
1515
route = "/..."
1616
[component.config]
17-
message = "I'm a {{object}}"
17+
message = "I'm a {{object}}"
18+
[component.build]
19+
command = "tinygo build -wasm-abi=generic -target=wasi -gc=leaking -no-debug -o main.wasm main.go"

examples/http-tinygo-outbound-http/readme.md renamed to examples/http-tinygo-outbound-http/README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ Creating and sending HTTP requests from Spin components closely follows the Go
1616
r1, err := spin_http.Get("https://some-random-api.ml/facts/dog")
1717
r2, err := spin_http.Post("https://postman-echo.com/post", "text/plain", bytes.NewBufferString("Hello there!"))
1818

19-
req, err := http.NewRequest("PUT", "https://postman-echo.com/put", bytes NewBufferString("General Kenobi!"))
20-
req.Header.Add("foo", "bar")
21-
r3, err := spin_http.Send(req)
19+
req, err := http.NewRequest("PUT", "https://postman-echo.com/put", bytes NewBufferString("General Kenobi!"))
20+
req.Header.Add("foo", "bar")
21+
r3, err := spin_http.Send(req)
2222
```
2323

2424
Building this as a WebAssembly module can be done using the `tinygo` compiler:
2525

2626
```shell
27-
$ make build
28-
tinygo build -wasm-abi=generic -target=wasi -gc=leaking -no-debug -o main.wasm main.go
27+
$ spin build
28+
Executing the build command for component tinygo-hello: tinygo build -wasm-abi=generic -target=wasi -gc=leaking -no-debug -o main.wasm main.go
29+
Successfully ran the build command for the Spin components.
2930
```
3031

3132
The component configuration must contain a list of all hosts allowed to send
@@ -42,13 +43,14 @@ source = "main.wasm"
4243
allowed_http_hosts = [ "https://some-random-api.ml", "https://postman-echo.com" ]
4344
[component.trigger]
4445
route = "/hello"
46+
[component.build]
47+
command = "tinygo build -wasm-abi=generic -target=wasi -gc=leaking -no-debug -o main.wasm main.go"
4548
```
4649

4750
At this point, we can execute the application with the `spin` CLI:
4851

4952
```shell
50-
$ make serve
51-
RUST_LOG=spin=trace,wasi_outbound_http=trace spin up --file spin.toml
53+
$ RUST_LOG=spin=trace,wasi_outbound_http=trace spin up
5254
```
5355

5456
The application can now receive requests on `http://localhost:3000/hello`:

examples/http-tinygo-outbound-http/spin.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
spin_version = "1"
22
authors = ["Fermyon Engineering <[email protected]>"]
33
description = "A simple Spin application written in (Tiny)Go that performs outbound HTTP requests."
4-
name = "spin-hello-tinygo"
4+
name = "spin-tinygo-outbound-http"
55
trigger = { type = "http", base = "/" }
66
version = "1.0.0"
77

examples/http-tinygo/readme.md renamed to examples/http-tinygo/README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Spin HTTP components in (Tiny)Go
1+
# Spin HTTP components in TinyGo
22

33
This example showcases how to build Spin HTTP components using TinyGo.
44

@@ -30,8 +30,9 @@ func main() {}
3030
Building this as a WebAssembly module can be done using the `tinygo` compiler:
3131

3232
```shell
33-
$ make build
34-
tinygo build -wasm-abi=generic -target=wasi -no-debug -o main.wasm main.go
33+
$ spin build
34+
Executing the build command for component tinygo-hello: tinygo build -wasm-abi=generic -target=wasi -gc=leaking -no-debug -o main.wasm main.go
35+
Successfully ran the build command for the Spin components.
3536
```
3637

3738
Finally, we can create a Spin application configuration to execute this
@@ -50,13 +51,14 @@ id = "hello"
5051
source = "main.wasm"
5152
[component.trigger]
5253
route = "/hello"
54+
[component.build]
55+
command = "tinygo build -wasm-abi=generic -target=wasi -gc=leaking -no-debug -o main.wasm main.go"
5356
```
5457

5558
At this point, we can execute the application with the `spin` CLI:
5659

5760
```shell
58-
$ make serve
59-
RUST_LOG=spin=trace spin up --file spin.toml
61+
$ RUST_LOG=spin=trace spin up
6062
```
6163

6264
The application can now receive requests on `http://localhost:3000/hello`:

examples/spin-wagi-http/http-rust/Cargo.lock

Lines changed: 31 additions & 87 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Spin component in TinyGo
2+
3+
```shell
4+
$ RUST_LOG=spin=trace spin build --up
5+
```
6+
7+
The application can now receive requests on `http://localhost:3000/publish`:
8+
9+
```shell
10+
$ curl -i localhost:3000/publish
11+
HTTP/1.1 200 OK
12+
content-length: 67
13+
date: Tue, 29 Nov 2022 07:03:52 GMT
14+
15+
mykey value was: myvalue
16+
spin-go-incr value: 1
17+
deleted keys num: 2
18+
```

examples/tinygo-redis/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Spin component in TinyGo
2+
3+
```shell
4+
$ RUST_LOG=spin=trace spin build --up
5+
```
6+
7+
```shell
8+
$ redis-cli
9+
127.0.0.1:6379> PUBLISH messages test-message
10+
(integer) 1
11+
```

examples/wagi-http-rust/spin.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ id = "env"
1010
source = "target/wasm32-wasi/release/wagihelloworld.wasm"
1111
[component.trigger]
1212
route = "/env"
13-
executor = { type = "wagi" } # _start (the default entrypoint) is automatically mapped to main()
13+
executor = { type = "wagi" } # _start (the default entrypoint) is automatically mapped to main()
14+
[component.build]
15+
command = "cargo build --target wasm32-wasi --release"

wit/ephemeral/wasi-cache.wit

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)