Our 16th Meetup at the 16th of February with a quick tour on Go 1.16 😊 . We will also have an outlook on the Go generics proposal.
Go 1.16 is expected to be released this Februrary! 🎉 🎆
io/ioutil gets deprecated
io and os insteadioutil functions will become wrappers around io and os, example ioutil.ReadFileGOOS=darwin, GOARCH=arm64
GO111MODULE=on is now the default, i.e. go tools work in go modules mode by defaultgo build and go test do not modify your go.mod, go.sum anymore
go get or go mod tidy to do tharuntime/metrics is a new package that provides a stable interface for accessing runtime metrics
runtime.ReadMemStats and othersGODEBUG=inittrace=1 prints execution time and memory allocation for all init calls, e.g. to analyze startup time regressionsnm <binary-file> (running strip <binary-file> will remove them all)embed packageembed) directory or its subdirectoriesstring, []byte or embed.FS
embed.FS when importing multiple (a tree of) files into a variableembed even when using string or []byte variables (use blank import `import _ “embed”)// go:embed pattern [pattern...] where paths use path.Match patterns
string and []byte can only have a single pattern// go:embed dir/* will embed dir/.foo but // go:embed dir will not!source .env && go run ./cmd/embed :12345strings on the binary shows that content is embedded as plain-textos and io/fsos.ReadDir/fs.ReadDir we get to new functions for listing directory contents
ioutil.ReadDir because they do not require to call stat for each directory entryos.scandirReadDir when walking directory trees you need to use filepath.WalkDir instead of filepath.Walk, filepath.WalkDir passes fs.DirEntry instead of os.FileInfo into the WalkFntype FS interface {
Open(name string) (File, error)
}io.FS filesystem abstraction interface
afero but it has a much larger interface (and functionality, e.g. supports writes)embed.FS implements this so you can easily work with embedded directory treestesting/fstest.MapFS is an in-memory file systemfs.FS and make your API filesystem agnostic, i.e. work transparently with a local directory, s3 block storage, remote file system etc.fstest.TestFStype DeleteFS interface {
FS
Delete(name string) error
}StatFS as an examplego2go translation tool from the dev.go2go branch of the Go repo (instructions)func print[T any](value T) {
fmt.Printf("type=%T\tvalue=%#v\n", value, value)
}
print([]int{1, 2, 3, 4})
print("Hello, Golang Leipzig!")[T any] is the type parameter list
any is a type constraint (limiting the set of allowed types that can be used for T)any means “unconstrained” or allow any type for Ttype Number interface {
type int, float64
}
func sum[T, S Number](a T, b S) S {
return S(a) + b
}
sum(1, 3.1415)