Skip to content

Instantly share code, notes, and snippets.

@up1
Last active December 18, 2024 15:15
Show Gist options
  • Save up1/69a6749df9464f15743dbb1a0c711762 to your computer and use it in GitHub Desktop.
Save up1/69a6749df9464f15743dbb1a0c711762 to your computer and use it in GitHub Desktop.
Go :: fieldalignment
$go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@latest
$fieldalignment -fix <package or filename>
// Before
func main() {
type first struct {
f float64
i int32
b bool
}
a := first{}
fmt.Println(unsafe.Sizeof(a)) // 24 bytes
}
$fieldalignment -fix demo.go
demo.go:9:13: struct of size 24 could be 16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment