Archive · Week 18 · Apr 27 – May 3, 2026from 2 items
The Go team accepted two proposals that extend the analysis framework and the SQL driver interface. Both changes add new APIs that can be used by tooling and drivers to improve safety and flexibility.
Worth knowingtooling
x/tools/go/analysis/passes/modernize analyzers
- What changed
- The proposal adds several new analyzers to the modernize pass:
atomic,embedlit,errorsastype,plusbuild,stringscut, andstditerators. - Production impact
- The source does not say.
- Try it
- Run
go vet -vettool=$(go env GOROOT)/bin/govetwith themodernizepass and observe the new diagnostics. - Source
- github.com/golang/go/issues/77986
Explain it and run it
Understand it, then run it
Run it now
// This program demonstrates the new modernize analyzers.
// It intentionally uses patterns that the analyzers will flag.
// Running `go vet -vettool=$(go env GOROOT)/pkg/tool/linux_amd64/vet`
// will show suggestions for atomic, embedlit, errorsastype,
// plusbuild, stringscut, and stditerators.
package main
import (
"errors"
"fmt"
"sync/atomic"
)
// atomic example: old sync/atomic usage
var counter int32
func inc() {
atomic.AddInt32(&counter, 1) // modernize will suggest atomic.Int32
}
// embedlit example: embedding a string literal
type Config struct {
Data string // modernize will suggest go:embed
}
// errorsastype example: converting error to any
func errToAny(err error) any {
return err // modernize will suggest errors.As
}
// plusbuild example: old build tag syntax
// +build ignore
// stringscut example: trimming a string
func trim(s string) string {
return s[:len(s)-1] // modernize will suggest strings.TrimSpace
}
// stditerators example: inefficient range loop
func sum(nums []int) int {
total := 0
for i := 0; i < len(nums); i++ { // modernize will suggest range
total += nums[i]
}
return total
}
func main() {
inc()
fmt.Println("counter:", counter)
c := Config{Data: "example"}
fmt.Println(c.Data)
err := errors.New("oops")
fmt.Println(errToAny(err))
fmt.Println(trim("hello "))
fmt.Println(sum([]int{1, 2, 3}))
}
What it printed when we ran it on Go 1.27.1
counter: 1 example oops hello 6
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.
Worth knowingstdlib
database/sql/driver: allow driver to entirely override Scan
- What changed
- The proposal introduces
sql.ConvertAssignand a newdriver.RowsColumnScannerinterface that lets drivers scan directly into user‑provided destinations. - Production impact
- The source does not say.
- Try it
- Implement a minimal driver that uses
RowsColumnScannerto scan a column into a custom type and observe the behavior. - Source
- github.com/golang/go/issues/67546
Exercise
Write a small program that uses the new sql.ConvertAssign function to copy a driver.Value into a custom struct field.
The 60-second version
This week the Go team added new tools and APIs that help developers write safer and more flexible code. First, the analysis framework now includes several new analyzers—atomic, embedlit, errorsastype, plusbuild, stringscut, and stditerators—so that static analysis can catch more subtle bugs and suggest modern idioms. Second, the database/sql package now exposes a ConvertAssign helper and a new RowsColumnScanner interface, allowing drivers to scan data directly into custom destination types. These changes give both tooling and drivers more power to enforce correctness and improve ergonomics, while keeping the core language unchanged.
Written by gpt-oss-20b · claims checked against the sources · archive, not individually reviewed