feat: initial add for (Tiny)Go SDK
Signed-off-by: Radu Matei <radu.matei@fermyon.com>
This commit is contained in:
parent
8c22c8d0a5
commit
d0f0f13a82
|
@ -3,3 +3,4 @@ target
|
|||
cache
|
||||
node_modules
|
||||
ignored-assets
|
||||
main.wasm
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
module github.com/fermyon/spin-sdk
|
||||
|
||||
go 1.17
|
|
@ -0,0 +1,17 @@
|
|||
package spin_http
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/cgi"
|
||||
)
|
||||
|
||||
// The entrypoint handler for a Spin HTTP component.
|
||||
//
|
||||
// This is currently handled using CGI to form the request and reponse,
|
||||
// but as Go implements support for the component model, the underlying
|
||||
// implementation of this function can change, but the exported signature
|
||||
// can continue to always be
|
||||
// `func Handler(h func(w http.ResponseWriter, r *http.Request)) error`.
|
||||
func Handler(h func(w http.ResponseWriter, r *http.Request)) error {
|
||||
return cgi.Serve(http.HandlerFunc(h))
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
.PHONY: build
|
||||
build:
|
||||
tinygo build -wasm-abi=generic -target=wasi -o main.wasm main.go
|
||||
|
||||
. PHONY: serve
|
||||
serve:
|
||||
RUST_LOG=spin=trace spin up --file spin.toml
|
|
@ -0,0 +1,11 @@
|
|||
module github.com/fermyon/spin/templates/spin-http-tinygo
|
||||
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/fermyon/spin-sdk v0.0.0
|
||||
)
|
||||
|
||||
replace (
|
||||
github.com/fermyon/spin-sdk v0.0.0 => ../../sdk/go/
|
||||
)
|
|
@ -0,0 +1,14 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
spin_http "github.com/fermyon/spin-sdk"
|
||||
)
|
||||
|
||||
func main() {
|
||||
spin_http.Handler(func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintln(w, "Hello, Fermyon!")
|
||||
})
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
apiVersion = "0.1.0"
|
||||
authors = ["Fermyon Engineering <engineering@fermyon.com>"]
|
||||
description = "A simple Spin application written in (Tiny)Go."
|
||||
name = "spin-hello-world"
|
||||
trigger = { type = "http", base = "/" }
|
||||
version = "1.0.0"
|
||||
|
||||
[[component]]
|
||||
id = "hello"
|
||||
source = "main.wasm"
|
||||
[component.trigger]
|
||||
route = "/hello"
|
||||
executor = { type = "wagi" }
|
Loading…
Reference in New Issue