-
Notifications
You must be signed in to change notification settings - Fork 478
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for wasi-http in the wasm binding. (#3007)
Co-authored-by: Alessandro (Ale) Segala <[email protected]>
- Loading branch information
1 parent
13dfbdb
commit 387c238
Showing
7 changed files
with
157 additions
and
8 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
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,4 @@ | ||
default: main.wasm | ||
|
||
main.wasm: main.go | ||
tinygo build -target wasi -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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package main | ||
|
||
// Building main.wasm: | ||
// go get github.com/dev-wasm/dev-wasm-go/http/client | ||
// tinygo build -target wasi -o main.wasm main.go | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"os" | ||
|
||
wasiclient "github.com/dev-wasm/dev-wasm-go/http/client" | ||
) | ||
|
||
func printResponse(r *http.Response) { | ||
fmt.Printf("Status: %d\n", r.StatusCode) | ||
body, err := ioutil.ReadAll(r.Body) | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
fmt.Printf("Body: \n%s\n", body) | ||
} | ||
|
||
func main() { | ||
client := http.Client{ | ||
Transport: wasiclient.WasiRoundTripper{}, | ||
} | ||
res, err := client.Get(os.Args[1]) | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
defer res.Body.Close() | ||
printResponse(res) | ||
} |
Binary file not shown.
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