diff --git a/examples/http-tinygo-outbound-http/outbound-http-to-same-app/go.mod b/examples/http-tinygo-outbound-http/outbound-http-to-same-app/go.mod new file mode 100644 index 0000000000..296ca67dbe --- /dev/null +++ b/examples/http-tinygo-outbound-http/outbound-http-to-same-app/go.mod @@ -0,0 +1,9 @@ +module outbound-http-to-same-app + +go 1.17 + +require github.com/fermyon/spin/sdk/go v0.0.0 + +require github.com/julienschmidt/httprouter v1.3.0 // indirect + +replace github.com/fermyon/spin/sdk/go v0.0.0 => ../../../sdk/go/ diff --git a/examples/http-tinygo-outbound-http/go.sum b/examples/http-tinygo-outbound-http/outbound-http-to-same-app/go.sum similarity index 100% rename from examples/http-tinygo-outbound-http/go.sum rename to examples/http-tinygo-outbound-http/outbound-http-to-same-app/go.sum diff --git a/examples/http-tinygo-outbound-http/outbound-http-to-same-app/main.go b/examples/http-tinygo-outbound-http/outbound-http-to-same-app/main.go new file mode 100644 index 0000000000..0c44b407a8 --- /dev/null +++ b/examples/http-tinygo-outbound-http/outbound-http-to-same-app/main.go @@ -0,0 +1,23 @@ +package main + +import ( + "fmt" + "net/http" + + spinhttp "github.com/fermyon/spin/sdk/go/http" +) + +func init() { + spinhttp.Handle(func(w http.ResponseWriter, r *http.Request) { + resp, err := spinhttp.Get("/hello") + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + fmt.Fprintln(w, resp.Body) + fmt.Fprintln(w, resp.Header.Get("content-type")) + }) +} + +func main() {} diff --git a/examples/http-tinygo-outbound-http/spin.toml b/examples/http-tinygo-outbound-http/spin.toml index d8a37a9461..8de9cfb21f 100644 --- a/examples/http-tinygo-outbound-http/spin.toml +++ b/examples/http-tinygo-outbound-http/spin.toml @@ -7,9 +7,23 @@ version = "1.0.0" [[component]] id = "tinygo-hello" -source = "main.wasm" -allowed_http_hosts = ["https://random-data-api.fermyon.app", "https://postman-echo.com"] +source = "tinygo-hello/main.wasm" +allowed_http_hosts = [ + "https://random-data-api.fermyon.app", + "https://postman-echo.com", +] [component.trigger] route = "/hello" [component.build] +workdir = "tinygo-hello" +command = "tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go" + +[[component]] +id = "outbound-http-to-same-app" +source = "outbound-http-to-same-app/main.wasm" +allowed_http_hosts = ["self"] +[component.trigger] +route = "/outbound-http-to-same-app" +[component.build] +workdir = "outbound-http-to-same-app" command = "tinygo build -target=wasi -gc=leaking -no-debug -o main.wasm main.go" diff --git a/examples/http-tinygo-outbound-http/go.mod b/examples/http-tinygo-outbound-http/tinygo-hello/go.mod similarity index 74% rename from examples/http-tinygo-outbound-http/go.mod rename to examples/http-tinygo-outbound-http/tinygo-hello/go.mod index 2c1b9e24bf..92fbf0342d 100644 --- a/examples/http-tinygo-outbound-http/go.mod +++ b/examples/http-tinygo-outbound-http/tinygo-hello/go.mod @@ -6,4 +6,4 @@ require github.com/fermyon/spin/sdk/go v0.0.0 require github.com/julienschmidt/httprouter v1.3.0 // indirect -replace github.com/fermyon/spin/sdk/go v0.0.0 => ../../sdk/go/ +replace github.com/fermyon/spin/sdk/go v0.0.0 => ../../../sdk/go/ diff --git a/examples/http-tinygo-outbound-http/tinygo-hello/go.sum b/examples/http-tinygo-outbound-http/tinygo-hello/go.sum new file mode 100644 index 0000000000..096c54e630 --- /dev/null +++ b/examples/http-tinygo-outbound-http/tinygo-hello/go.sum @@ -0,0 +1,2 @@ +github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= +github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= diff --git a/examples/http-tinygo-outbound-http/main.go b/examples/http-tinygo-outbound-http/tinygo-hello/main.go similarity index 100% rename from examples/http-tinygo-outbound-http/main.go rename to examples/http-tinygo-outbound-http/tinygo-hello/main.go