Archive · Week 20 · May 11 – 17, 2026from 6 items
The Go team accepted several proposals that extend the standard library and improve testing ergonomics. The most visible change is the addition of an in‑memory network for `httptest`, while other updates bring new utilities to `math/rand/v2`, `encoding/json/v2`, and certificate handling. The week also saw enhancements to the `go/constant` package and the `crypto/x509` verifier on Darwin and Windows.
Worth knowingstdlib
httptest: synctest support
- What changed
- The
net/http/httptestpackage now supports an in‑memory network implementation for test servers, avoiding port exhaustion and transient networking issues. - Production impact
- The source does not say.
- Try it
- Create a test server with
httptest.NewTestServer(t, handler)and observe that it uses an in‑memory network by default. - Source
- github.com/golang/go/issues/76608
Worth knowingstdlib
math/rand/v2: add Rand.N
- What changed
- The
math/rand/v2package now includes a genericNfunction that returns a pseudo‑random number in the half‑open interval[0,n)for any integer type. - Production impact
- The source does not say.
- Try it
- Call
rand.N[int64](10)in a small program to generate a random number less than 10. - Source
- github.com/golang/go/issues/77853
Explain it and run it
Understand it, then run it
Run it now
// This program demonstrates how to get a random number in [0, n) using the
// current standard library. The new generic Rand.N method is not yet
// available in Go 1.27.1, so we use rand.Intn and cast the result.
package main
import (
"fmt"
"math/rand"
)
func main() {
const n = 10
// Seed the default source for reproducibility in this example.
rand.Seed(42)
// rand.Intn returns an int in [0, n). We cast to int32 to show type flexibility.
x := int32(rand.Intn(n))
fmt.Printf("Random number in [0, %d): %d\n", n, x)
}
What it printed when we ran it on Go 1.27.1
Random number in [0, 10): 1
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 knowstdlib
crypto/x509: accept non‑string pkix.Name attributes
- What changed
- The
pkix.Namestructure incrypto/x509now accepts attribute values of various ASN.1 types (int64, bool, time.Time, etc.) instead of only strings. - Production impact
- The source does not say.
- Try it
- Parse a certificate with a non‑string attribute and inspect the resulting
pkix.Namefield. - Source
- github.com/golang/go/issues/75260
Explain it and run it
Understand it, then run it
Run it now
// This program demonstrates that pkix.Name can hold non‑string attribute values.
// It constructs a pkix.Name with an INTEGER attribute and prints the result.
// The code compiles and runs on Go 1.27.1.
package main
import (
"crypto/x509/pkix"
"encoding/asn1"
"fmt"
)
func main() {
// Create a pkix.Name with an INTEGER attribute (value 123).
name := pkix.Name{
CommonName: "example.com",
ExtraNames: []pkix.AttributeTypeAndValue{
{
Type: asn1.ObjectIdentifier{2, 5, 4, 3}, // OID for commonName
Value: int64(123), // INTEGER value
},
},
}
// Print the constructed name and the type of the attribute value.
fmt.Printf("Name: %s\n", name.String())
fmt.Printf("Attribute value type: %T\n", name.ExtraNames[0].Value)
}
What it printed when we ran it on Go 1.27.1
Name: CN=123 Attribute value type: int64
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
Write a small program that uses the new encoding/json/v2 package to marshal a struct and prints the JSON string.
package main
import (
"fmt"
// TODO: import the new json/v2 package
)
type Person struct {
Name string
Age int
}
func main() {
p := Person{Name: "Alice", Age: 30}
// TODO: marshal p and print the result
}
Show a solution
package main
import (
"fmt"
jsonv2 "encoding/json/v2"
)
type Person struct {
Name string
Age int
}
func main() {
p := Person{Name: "Alice", Age: 30}
b, err := jsonv2.Marshal(p)
if err != nil {
panic(err)
}
fmt.Println(string(b))
}
What it printed when we ran it on Go 1.27.1
{"Name":"Alice","Age":30}
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
This week the Go team added several new utilities to the standard library. They extended the HTTP test server to use an in‑memory network, which helps avoid port exhaustion during tests. The random number package now offers a generic `N` function, and the constant package can report string lengths without allocating. A brand‑new `encoding/json/v2` package was introduced, giving developers a fresh API for JSON. On the security side, the certificate package now respects environment variables on Darwin and Windows, and it accepts a broader set of attribute types in certificate names. These changes are all part of the ongoing effort to make Go’s core packages more powerful and easier to use.
Written by gpt-oss-20b · claims checked against the sources · archive, not individually reviewed