WasmEdge for Go Developers

• 2 minutes to read

Go developers can benefit from WebAssembly and WasmEdge Runtime in two important ways. You can compile Go programs to run in the WasmEdge container, or embed external functions, written in multiple programming languages, into Go applications as plug-ins. Get started by installing WasmEdge or using the WasmEdge development Docker.

Embed WasmEdge in Go applications

WasmEdge enables Go developers to embed functions and plug-ins written in different languages, including Rust, Swift, Kotlin, C/C++, JavaScript and TinyGo, into their Go applications. The WasmEdge Go SDK can be called from any Go host application to run arbitary WebAssembly functions and to return the results back to the Go host application.

Learning resources:

Integrations and use cases:

  • YoMo: Streaming image recognition using WebAssembly embedded functions (Tutorial | Source code)
  • Dapr: Creating microservices (Tutorial | Source code)
  • Reactr: An easy-to-use framework to embed WasmEdge functions into Go applications (Source code)
  • MOSN: A service mesh API proxy that can be extended by WasmEdge programs – coming soon!

The standard Go plug-in system is based on shared libraries and has many issues. The plug-in is not isolated from the host and hence is not safe. The WasmEdge approach allows safe mixing of plug-ins written in different languages for different systems.

Run Go programs in WasmEdge

WebAssembly is a ploygot runtime that supports many front-end programming languages. Compiling your Go program to WebAssembly allows the Go program to run efficiently and safely across all OS and hardware platforms WasmEdge supports. It is more secure and portable than the default native client (NaCl) compiling targets for Go programs. It allows Go applications to be easily managed by container tools such as Kubernetes without the overhead of Docker and guest Linux. WasmEdge also makes it possible to embed Go functions into other applications (e.g., a Go host app as above or a Node.js host app).

However, it is still difficult to run standard Go programs without change to WebAssembly since Go requires a runtime enviornment that handles issues like GC. If you would like to create a Go runtime for WebAssembly, please get in touch! We would like to see that!

Current solution: You can use TinyGo. It supports almost all Go language syntax and compiles easily to WebAssembly.

WebAssemblySDKgolang
A high-performance, extensible, and hardware optimized WebAssembly Virtual Machine for automotive, cloud, AI, and blockchain applications