News for hackers. Stuff that matters.
Re:Go 1.22 Release Notes by cookiengineer on Wednesday February 07, 2024 @01:01AM (#39285044)
I feel very similar to your experience.

What made me stay in go is its amazingly unified build toolchain. The things you can do with go:embed and go:generate blow my mind in every other project.

The golang.org/x package is also another thing, where there is pretty much every internet RFC related implementation available, ready to use.

Re:Go 1.22 Release Notes by avtolik on Wednesday February 07, 2024 @03:47AM (#39286092)
Can you give some examples how are you using go:embed and go:generate?
Re:Go 1.22 Release Notes by bheadmaster on Wednesday February 07, 2024 @04:00AM (#39286174)
One example that comes to mind is building a single-binary full-stack application.

You can use whatever frontend framework you want, and just embed the html/css/js/asset files inside the binary with go:embed. In case of dynamic set of files, you can also write a Go utility to generate the embeddings with go:generate.

In addition to the ease of distribution (no more assets/ directory - just a single binary executable!), it also increases speed of the application, as it no longer has to perform file system reads in order to serve a webpage.

Re:Go 1.22 Release Notes by jadayesnaamsi on Wednesday February 07, 2024 @05:41AM (#39286887)
A good example of a Go project using embed to pack its html/css/js assets in a single binary is PocketBase:

https://github.com/pocketbase/pocketbase/blob/master/ui/embe...

Re:Go 1.22 Release Notes by heywire on Wednesday February 07, 2024 @06:59AM (#39287480)
Last I checked, AdGuard Home also did this.

https://github.com/AdguardTeam/AdGuardHome

Re:Go 1.22 Release Notes by gotbeans on Wednesday February 07, 2024 @04:03AM (#39286205)
Not OP, used embedded to add ebpf code compiled for a project, helps to only ship the binary. Same thing for shipping swagger static html stuff to host an OpenAPI server.
Re:Go 1.22 Release Notes by maccard on Wednesday February 07, 2024 @04:51AM (#39286530)
We use go:generate to generate services and types from protobufs.

    //go:generate protoc --go_out=src/generated/ protos/service.proto
Our CI pipeline is a dockerfile that looks vaguely like this:

    FROM golang:1.21 as build
    go generate
    go build
    go test

    FROM scratch
    COPY --from=build ...
The CI steps are: docker build <XXXX> && docker push <XXXX>

We have a goland project template that has options for generate, build, test that matches what we do in CI rather than having that _one_ edge case that is the difference between `make build` and `go build`. That difference has caused more than one outage in my career.

Re:Go 1.22 Release Notes by Cthulhu_ on Thursday February 08, 2024 @09:41AM (#39302445)
I've used go:generate to generate a set of structs based on an XSLT document. That said, since XML is fairly uncommon these days in popularity, the generator was a bit buggy still.

And I've used go:embed to include .sql files for database migrations and querying. I should really spend some time on this POC I made (sqlite, goose for migrations, and an implementation of temporal tables) and publish it as a demo.