-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* grand Go SDK update - Add `outbound-redis` set operations and `execute` function - Add `key-value` support - Remove `*_free` calls since they were buggy and unnecessary given that we tell `tinygo` to leak anyway - Remove `-wasm-abi=generic` option since it's been removed as of `tinygo` 0.27 Signed-off-by: Joel Dice <[email protected]> * fix Go CI issues - Update Go and `tinygo` versions - Use `interface{}` instead of `any` for broader compatibility - Make `tinygo-outbound-redis` example sort the `SMEMBERS` result before comparing with the expected value Signed-off-by: Joel Dice <[email protected]> * rename Go SDK key-value directory to key_value Signed-off-by: Joel Dice <[email protected]> --------- Signed-off-by: Joel Dice <[email protected]>
- Loading branch information
Showing
35 changed files
with
1,224 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,7 +63,7 @@ inputs: | |
type: bool | ||
golang-version: | ||
description: 'golang version to setup' | ||
default: '1.17' | ||
default: '1.20' | ||
required: false | ||
type: string | ||
|
||
|
@@ -82,10 +82,10 @@ inputs: | |
description: 'setup tinygo' | ||
required: false | ||
default: 'false' | ||
type: bool | ||
type: bool | ||
tinygo-version: | ||
description: 'tinygo version to setup' | ||
default: 'v0.22.0' | ||
default: 'v0.27.0' | ||
required: false | ||
type: string | ||
|
||
|
@@ -150,4 +150,4 @@ runs: | |
uses: rajatjindal/setup-actions/[email protected] | ||
if: ${{ inputs.tinygo == 'true' }} | ||
with: | ||
version: ${{ inputs.tinygo-version }} | ||
version: ${{ inputs.tinygo-version }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Spin component in TinyGo | ||
|
||
```shell | ||
$ RUST_LOG=spin=trace spin build --up | ||
``` | ||
|
||
The application can now receive requests on `http://localhost:3000/test`: | ||
|
||
```shell | ||
$ curl -i localhost:3000/test | ||
HTTP/1.1 200 OK | ||
content-length: 67 | ||
date: Tue, 29 Nov 2022 07:03:52 GMT | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module github.com/fermyon/spin/templates/spin-http-tinygo-key-value | ||
|
||
go 1.17 | ||
|
||
require github.com/fermyon/spin/sdk/go v0.0.0 | ||
|
||
replace github.com/fermyon/spin/sdk/go v0.0.0 => ../../sdk/go/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package main | ||
|
||
import ( | ||
"net/http" | ||
"reflect" | ||
"fmt" | ||
|
||
spin_http "github.com/fermyon/spin/sdk/go/http" | ||
"github.com/fermyon/spin/sdk/go/key_value" | ||
) | ||
|
||
func init() { | ||
|
||
// handler for the http trigger | ||
spin_http.Handle(func(w http.ResponseWriter, r *http.Request) { | ||
store, err := key_value.Open("default"); | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
defer key_value.Close(store) | ||
|
||
if err := key_value.Set(store, "foo", []byte("bar")); err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
{ | ||
expected := []byte("bar") | ||
if value, err := key_value.Get(store, "foo"); err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} else if !reflect.DeepEqual(value, expected) { | ||
http.Error( | ||
w, | ||
fmt.Sprintf("expected %v, got %v", expected, value), | ||
http.StatusInternalServerError, | ||
) | ||
return | ||
} | ||
} | ||
|
||
{ | ||
expected := []string{"foo"} | ||
if value, err := key_value.GetKeys(store); err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} else if !reflect.DeepEqual(value, expected) { | ||
http.Error( | ||
w, | ||
fmt.Sprintf("expected %v, got %v", expected, value), | ||
http.StatusInternalServerError, | ||
) | ||
return | ||
} | ||
} | ||
|
||
if err := key_value.Delete(store, "foo"); err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
if exists, err := key_value.Exists(store, "foo"); err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} else if exists { | ||
http.Error(w, "key was not deleted as expected", http.StatusInternalServerError) | ||
return | ||
} | ||
}) | ||
} | ||
|
||
func main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
spin_version = "1" | ||
authors = ["Fermyon Engineering <[email protected]>"] | ||
name = "tinygo-key-value-example" | ||
trigger = { type = "http", base = "/" } | ||
version = "0.1.0" | ||
|
||
[[component]] | ||
id = "key-value" | ||
source = "main.wasm" | ||
key_value_stores = ["default"] | ||
[component.trigger] | ||
route = "/test" | ||
[component.build] | ||
command = "tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
golang.org/x/exp v0.0.0-20230213192124-5e25df0256eb h1:PaBZQdo+iSDyHT053FjUCgZQ/9uqVwPOcl7KSWhKn6w= | ||
golang.org/x/exp v0.0.0-20230213192124-5e25df0256eb/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.