-
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.
- Loading branch information
1 parent
608e4cb
commit b97a328
Showing
6 changed files
with
150 additions
and
7 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,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