Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tinygo http client + wasmtime #4738

Open
scottctaylor12 opened this issue Feb 14, 2025 · 0 comments
Open

tinygo http client + wasmtime #4738

scottctaylor12 opened this issue Feb 14, 2025 · 0 comments
Labels
wasm WebAssembly

Comments

@scottctaylor12
Copy link

I am attempting to write a wasip2 module that makes http requests.

Code:

package main

import (
	"fmt"
	"io"
	"log"
	"net/http"
)

func main() {
	resp, err := http.Get("https://ifconfig.so")
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()

	body, err := io.ReadAll(resp.Body)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(string(body))
}

I compile my program with tiny go using the following command:
tinygo build -o main.wasm -target=wasip2 main.go

Then I attempt to run my wasi module with wasmtime using the following command:
wasmtime run -S http=y main.wasm

I expect to get an IP address returned from the web request. Instead, I receive a message stating:
Netdev not set

I'm struggling to figure out how to write WASI 2.0 modules in go that make http requests. Is there any guidance on how to do this?

@deadprogram deadprogram added the wasm WebAssembly label Feb 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasm WebAssembly
Projects
None yet
Development

No branches or pull requests

2 participants