使用gRPC Web进行Go WebAssembly

huangapple go评论87阅读模式
英文:

Go WebAssembly with gRPC Web

问题

我想使用主要使用Go编写的WebAssembly制作一个网站,并且我想使用gRPC协议。由于Web的限制,我必须使用gRPC的“Web版本协议”,它可以编译为JavaScript库。请问我如何在Go中编译这个“Web版本”呢?我找到了这个有用的编译工具:https://github.com/namely/docker-protoc

英文:

I want to make a website using webassembly written mainly in go, and I would like to use grpc protocol, due the web restrictions, I have to use the "web version protocol" of grpc, and it can be compiled to js library, and how can I compile the "web version" in go?
I found this useful to compile: https://github.com/namely/docker-protoc

答案1

得分: 3

有趣的问题,但我认为你目前还不能这样做。

存在两个问题:

  1. 浏览器中的WASM目前无法访问Web API。
  2. 唯一的gRPC-Web SDK是JavaScript的(而且,由于浏览器中的WASM无法访问Web API,即使你用Golang编写了一个SDK,当你将应用程序编译为WASM时,在浏览器中也无法正常工作)。
英文:

Interesting question but I think (!?) you can't yet do this.

There are >2 issues:

  1. WASM in the browser is currently unable (!?) to access Web APIs.
  2. The only gRPC-Web SDK is JavaScript (and, since WASM in the browser can't access Web APIs, even if you wrote one in Golang, when you compiled apps using it to WASM, the wouldn't work in the browser)

huangapple
  • 本文由 发表于 2021年10月1日 06:31:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/69399452.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定