TIL What's New in Go 1.16 and how to use it in a Docker Container
This'll be brief.
Go 1.16
Check out the release notes.
Some highlights:
Embed files directly into variables at compile time
The embed package lets you embed files directly into variables using a simple directive -- at compile time. In the past, you'd have to declare a `var` and the use an `init()` function (or other function) to load the contents of a file into that var -- all of which happens at runtime and is subject to issues. What's worse: if your application was a docker container, then you'd have had to make sure the final, runnable container had that file in there, too, by using a `COPY` directive.
Go install replaces Go get as a way to install CLIs
From the docs:
go
install
, with or without a version suffix (as described above), is now the recommended way to build and install packages in module mode.go
get
should be used with the-d
flag to adjust the current module's dependencies without building packages, and use ofgo
get
to build and install packages is deprecated. In a future release, the-d
flag will always be enabled.
What does this mean? To quote a friend,
Using Go 1.16 in a Docker container
It's easy... the `golang:alpine` image already points to `1.16`. See Docker Hub.
Comments
Post a Comment