Archive · Week 7 · Feb 10 – 16, 2025from 4 items
The Go team released the 1.24 major version and added a new RSA helper that lets callers pick different hash functions for OAEP and MGF1. The community blog highlighted WebAssembly enhancements and the new release’s features.
Nice to knowtooling
Extensible Wasm Applications with Go
- What changed
- Go 1.24 adds function export and reactor mode support for WebAssembly.
- Production impact
- The source does not say.
- Try it
- Build a small Wasm module that exports a Go function and run it in a browser.
- Source
- go.dev/blog/wasmexport
Explain it and run it
Understand it, then run it
Run it now
// This program demonstrates that the //go:wasmexport directive is ignored
// in Go 1.27.1. The function is not exported to a WebAssembly module,
// so we simply call it directly from Go and print the result.
package main
import "fmt"
//go:wasmexport add
func add(a, b int32) int32 { return a + b }
func main() {
// Call the function directly; it behaves normally in Go.
res := add(3, 4)
fmt.Printf("add(3, 4) = %d\n", res)
}
What it printed when we ran it on Go 1.27.1
add(3, 4) = 7
After the change ships
go · the proposal's code; it does not compile until the change ships
// This code uses the go:wasmexport directive and builds a WASI reactor.
// It will not compile until Go 1.24 is released.
package main
//go:wasmexport add
func add(a, b int32) int32 {
return a + b
}
func main() {
// No runtime logic needed; the host will call _initialize and then
// invoke the exported function "add" as many times as desired.
}
Run sends this program (for Solidity, the contract and its tests) to our own sandbox, where it is compiled and run once, with no network, and what it printed or the test report comes back here. Nothing is kept. Runs are counted per visitor for the day so everyone gets a turn; the details are on the legal page.
Nice to knowecosystem
Go 1.24 is released!
- What changed
- The blog post summarizes Go 1.24’s new features, including generic type aliases, map performance, and FIPS 140 compliance.
- Production impact
- The source does not say.
- Try it
- Read the blog to learn about the new language features.
- Source
- go.dev/blog/go1.24
Explain it and run it
Understand it, then run it
Run it now
// This program demonstrates the new generic type alias feature introduced in Go 1.24.
// It defines a generic alias for a map type and uses it to store and retrieve values.
package main
import "fmt"
// Generic type alias: a map from K to V, where K must be comparable.
type MyMap[K comparable, V any] = map[K]V
func main() {
// Create a MyMap[int, string] and populate it.
m := MyMap[int, string]{}
m[1] = "one"
m[2] = "two"
// Print the map contents.
for k, v := range m {
fmt.Printf("%d -> %s\n", k, v)
}
}
What it printed when we ran it on Go 1.27.1
1 -> one 2 -> two
Run sends this program (for Solidity, the contract and its tests) to our own sandbox, where it is compiled and run once, with no network, and what it printed or the test report comes back here. Nothing is kept. Runs are counted per visitor for the day so everyone gets a turn; the details are on the legal page.
Exercise
Exercise – Export a Go function to WebAssembly
Write a Go program that declares a function annotated with //go:wasmexport. The function should add two int32 values and return the result. In the main function, simply call this exported function (as a normal Go function) and print the result. The exercise demonstrates how the go:wasmexport directive is used in source code, even though we are not actually compiling to Wasm in the sandbox.
package main
//go:wasmexport add
func add(a, b int32) int32 {
// TODO: implement the addition
return 0
}
func main() {
// TODO: call add and print the result
}
Show a solution
package main
//go:wasmexport add
func add(a, b int32) int32 {
return a + b
}
func main() {
x, y := int32(7), int32(5)
result := add(x, y)
println("add(", x, ",", y, ") =", result)
}
What it printed when we ran it on Go 1.27.1
(it printed nothing)
Run sends this program (for Solidity, the contract and its tests) to our own sandbox, where it is compiled and run once, with no network, and what it printed or the test report comes back here. Nothing is kept. Runs are counted per visitor for the day so everyone gets a turn; the details are on the legal page.
The 60-second version
Hello, I’m here to share what the Go team has been working on this week. They’ve just rolled out Go 1.24, a major release that brings a host of improvements—from faster maps and new generic type aliases to FIPS 140 compliance. In the standard library, a new RSA helper, `EncryptOAEPWithOptions`, lets you pick separate hash functions for the OAEP padding and the MGF1 mask generation, a feature that’s handy for Android Keystore integration. The team also announced WebAssembly enhancements, adding function export and reactor mode support, opening new possibilities for Go in the browser. That’s the snapshot of this week’s progress.
Written by gpt-oss-20b · claims checked against the sources · archive, not individually reviewed