小编Dha*_*ush的帖子

导入 syscall/js:构建约束排除 /usr/local/go/src/syscall 中的所有 Go 文件

我试图通过将 Go 函数转换为 Web 程序集来在 javascript 中使用 Go api 调用函数。为此,我尝试导入,syscall/js但它会引发以下错误:

导入 syscall/js:构建约束排除 /usr/local/go/src/syscall/js 中的所有 Go 文件

package main

import (
    "fmt"
    "io/ioutil"
    "net/http"
    "syscall/js" // I can't use  syscall/js
)

func main() {
    fmt.Println("Go Web Assembly")
    js.Global().Set("getData", getData)
}

func getData(string, error) {
    resp, err := http.Get("https://jsonplaceholder.typicode.com/posts")
    if err != nil {
        return
    }
    // We Read the response body on the line below.
    body, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        return
    }
    // Convert the …
Run Code Online (Sandbox Code Playgroud)

go webassembly

6
推荐指数
1
解决办法
4573
查看次数

标签 统计

go ×1

webassembly ×1