Announcing Go support for Wasm Workers Server
When we started Wasm Workers Server (wws) a few months ago, a core idea of the project was to help you develop serverless applications in the language of your choice. It currently supports multiple languages including Rust, Python, and Ruby.
WebAssembly (Wasm) is the foundation for this ecosystem. You can compile many languages and interpreters into a Wasm module. The missing step is an SDK that enables the interoperability between your code and wws
.
Fortunately, wws
and Wasm have a vibrant community. Today, we are happy to announce Go support thanks to a contribution from Mohammed Nafees.
Your first worker in Go
To create your first worker in Go, you need to install the following tools:
TinyGo is used to compile the Go source code into Wasm32 / WASI. It is a temporary approach as the Go team is actively working on native Wasm32 / WASI support.
After you install all prerequisites, you can create a simple worker:
-
Initialize a Go project:
go mod init worker
-
Add the Wasm Workers Server Go SDK:
go get -u github.com/vmware-labs/wasm-workers-server/kits/go/worker
-
Create a
worker.go
file with the following contents:package main
import (
"net/http"
"github.com/vmware-labs/wasm-workers-server/kits/go/worker"
)
func main() {
worker.ServeFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("x-generated-by", "wasm-workers-server")
w.Write([]byte("Hello from Wasm!"))
})
} -
Compile your worker with TinyGo:
tinygo build -o index.wasm -target wasi worker.go
-
Install Wasm Workers Server (if you don't have it yet):
curl -fsSL https://workers.wasmlabs.dev/install | bash
-
Run the project:
wws .
-
Access http://localhost:8080.
Congratulations! You just created your first worker in Go ๐.
Examples and more features
At this point, we recommend you check the Go documentation written by Mohammed. There, you can find more examples and guides to develop more complex workers in Go:
What's next?
We are always looking to add support for more programming languages. Wasm allows you to combine many languages in a single application, and we want you to take advantage of this.
What are the languages you would like to see in Wasm Workers Server? Feel free to open a new issue in our repository or ping us on Twitter. We already have some languages like PHP and Zig in our roadmap. There are also some experiments around supporting Java, so you can expect an SDK in the future.
If you are brave to code your own SDK, you can help grow the project. As Mohammed did, you can develop a new shiny SDK for Wasm Workers Server ๐คฉ. We asked him what was his motivations to contribute to Wasm Workers Server in case you identify yourself:
I was in search for a Wasm project that is both easy to use but also mature enough to extend and learn about Wasm itself and thatโs what got me interested in Wasm Workers Server.
The excellently designed core architecture of Workers Server makes it so adaptable that I love it. With the new Go support, I am using it to host Wasm serverless functions for some of my repeatable daily tasks.
I intend to play around it more and explore the possibilities that it can bring forward with it.
Bringing communities together
It's clear that everyone has a personal preference for programming languages. You may feel more productive in a specific language while wanting to learn a new one.
In Wasm Workers Server you can choose your preferred language and combine it with others. Thanks to the community, the number of supported languages is growing.
And this is just the beginning. Stay tuned for updates in the Wasm Workers Server's repository and our Twitter ๐.