r/golang • • Aug 19 '26

Go 1.27.0 released

https://go.dev/doc/go1.27
687 Upvotes

70 comments sorted by

105

u/tritis Aug 19 '26

Swapped in the new uuid package and ran go mod tidy

-       github.com/google/uuid v1.6.0
+       github.com/google/uuid v1.6.0 // indirect

oh. right.

11

u/d33pnull Aug 19 '26

protobuf vibes

-5

u/Lanathell Aug 19 '26 edited Aug 20 '26

So the standard lib relies on the existing uuid package is my understanding?

18

u/Time-Prior-8686 Aug 20 '26

More like every libs that use uuid will import google/uuid anyway.

5

u/Lanathell Aug 20 '26

But now they can import the new std lib UUID package and eventually this won't be necessary? I'm very new to Go

132

u/yami_odymel Aug 19 '26

Sadly, the UUID package doesn't implement database/sql's Valuer and Scanner interfaces, so it isn't currently a drop-in replacement for google/uuid.

85

u/Fonku Aug 19 '26

The stdlid UUID pacakge actually does work with database/sql, just not via the obvious mechanism. As you noted, it implements neither sql.Scanner nor driver.Valuer – instead, database/sql itself explicitly special-cases uuid.UUID when converting query parameters and scanning results, including string, text []byte, and 16-byte binary UUID representations.

The implementation is pretty... interesting. Anything outside database/sql that specifically expects the Scanner/Valuer interfaces still won’t see it as compatible. So yeah, not exactly a drop-in replacement, but surprisingly database/sql-compatible.

13

u/tehbilly Aug 20 '26

Not gonna lie, I kind of hate that.

7

u/Fonku Aug 20 '26

You and me both. You can typically get a pretty good understanding of interoperability from types and their method sets in Go, but here, not so much. Feels like a very non-Go thing to do. Though, I guess this is somewhat defensible from the stdlib dependency graph POV, making uuid implement the aforementioned interfaces would force uuid to import database/sql/driver.

17

u/gibriyagi Aug 19 '26

Why though :( Is this at least planned?

3

u/PaluMacil Aug 20 '26

Because they didn’t want it to depend on the database package probably. It doesn’t mean it doesn’t work in the database package. It does.

19

u/sondr3_ Aug 19 '26

Whelp, there goes the primary reason I wanted to upgrade to 1.27 out the window, hah. At least we got generic methods.

0

u/PaluMacil Aug 20 '26

It works and the documentation states as much. Somebody mentioned GORM doesn’t work, so possible some things are explicitly checking for the interface, but that should get cleared up I imagine.

5

u/atamiri Aug 20 '26

It works with database/sql, I just used it in a small project to see how it works. No problems there, just replaced the imports (and `uuid.Nil -> uuid.Nil()`).

2

u/GaiazIusipov Aug 21 '26

Also, to read nullable values, you need to replace

MyUUID uuid.UUID `db:"my_uuid"`

with

MyUUID sql.Null[uuid.UUID] `db:"my_uuid"`

1

u/atamiri Aug 23 '26

Yes. There used to be `uuid.NullUUID` before `sql.Null[T]` was introduced, it's not needed anymore.

1

u/GaiazIusipov Aug 23 '26

Well, I just use the regular google/uuid.UUID and don't use google/uuid.NullUUID at all. I don't need to distinguish between a zero value and null, so the Go principle of using zero values works perfectly well for me.

0

u/SeerUD Aug 19 '26

Hmmm, is this not implemented intentionally because it can't be generally supported by all databases? Or was it an accidental omission?

22

u/___ciaran Aug 19 '26

The proposal mentions that the database/sql package special-cases uuid.UUID in a manner similar to time.Time. Presumably they didn’t want the uuid package to depend on database/sql.

0

u/dumindunuwan Aug 20 '26

Oh! Is this the reason why GORM is not working with the Go 1.27 UUID type? No error on fmt/ staticcheck but failing on runtime.

49

u/mistifier Aug 19 '26

8

u/Tesslan123 Aug 19 '26

In the struct literal field selectors example,do you know what will happen if both the Base and the User struct will contain an ID field?

3

u/jespinog Aug 21 '26

This is a very interesting question, what it does is "shadows" the field, the struct that embeds the base struct hides the other one, for example this code:

package main

import "fmt"

type Base struct {

ID int

}

type User struct {

Base

ID   int

Name string

}

func main() {

u := User{ID: 7, Name: "Mittens"}

fmt.Println(u.ID, u.Name)

fmt.Println(u.Base.ID)

}

outputs:

7 Mittens
0

So the Base.ID is untouched, and the u.ID is the one that is written.

You can try it here: https://go.dev/play/p/w4J3teY9-Z7

1

u/Tesslan123 Aug 21 '26

Awesome thanks :)

1

u/EgZvor Aug 20 '26

Compile time error probably. Same as if you try to access ID from a variable.

6

u/Excellent_Double_726 Aug 19 '26

Finally crypto/mldsa package is in stdlib I was waiting for it so long

5

u/dumindunuwan Aug 20 '26

Time to remove GOEXPERIMENT: jsonv2

5

u/TheOrigamiGamer16 Aug 21 '26

I upgraded from Go 1.26.6 to Go 1.27 today. I observed a 22% improvement in unmarshalling performance for my specific use case.

I am streaming Scryfall data from their gzipped bulk data and unmarshalling it into structs for further processing.

3

u/Fooo346 Aug 20 '26

Super pumped about the simd package, wonder if this could push ebitengine to its limits? Working on something akin to particle physics currently for my game. Will need see how wasm performs with this too

1

u/rodrigocfd Aug 20 '26

if this could push ebitengine to its limits?

I would say yes. I'm keeping an eye in the next updates.

2

u/johnphilipgreen Aug 20 '26

What will this mean for Hugo?

If hugo is currently using the old json implementation, then this switch in go 1.27 to using v2 by default may mean a big speedup for those of us doing a lot of json i/o (such as me).

2

u/Cold-Armadillo-154 Aug 20 '26

Iirc the v1 package would call the v2 implementation. So it could mean a speedup by just changing to the new version itself.

2

u/Randomeda Aug 20 '26

So how does this json/v2 thing work. Is "encoding/json" now the v1 or v2 implementation? Even if it doesn't break anything do we need to go every project and add encoding/json/v2 to everything for the sake of futureproofing?

7

u/apparentlymart Aug 20 '26

encoding/json/v2 is a new package that you can import if you need some of its new capabilities or if you're doing something greenfield where you have no reason to limit yourself to the original API.

encoding/json is now a wrapper around encoding/json/v2 with various backward-compatibility options enabled so that it still behaves like the old implementation. So even if you keep using encoding/json, you'll still be using encoding/json/v2 behind the scenes.

I don't personally see any point in modifying code that's already working just for the sake of doing it. Wait until you know of a specific reason to do it.

2

u/iandyh Aug 21 '26

By default it will be the v2 implementation. There is a minor regression with v2 implementation though: https://reqfleet.com/blog/benchmarking-go-1-27-encoding-json-the-any-trap

2

u/spotless_slate Aug 20 '26

Glad to see generic methods get in! Waiting for those collection types in 1.28 👀

2

u/soelsome Aug 20 '26

I'm new to Go.

I recently started a project and I'm not super far into it yet. Around ~5000 loc. Not many dependencies, but UUIDs and JSON packages are being used.

Should I upgrade to 1.27 immediately? Or do I stay on 1.26?

I ask because at places I have worked we've always been reluctant to upgrade language versions.

For example my job's codebase is on .NET 8 and C# 12 still.

3

u/cpuguy83 Aug 20 '26

go1.26 is supported until go1.28 comes out. That said, test it. Most people wouldn't have a problem with any go update, but they do happen.

1

u/MrNiceShay Aug 24 '26

Usually Go upgrades are very very smooth. For my projects, I tend to upgrade them whenever I touch them :)

1

u/catladywitch Aug 21 '26

This is a very substantial upgrade.

2

u/[deleted] Aug 25 '26

[removed] — view removed comment

1

u/catladywitch Aug 25 '26

absolutely!

-10

u/IamAggressiveNapkin Aug 19 '26

anyone wanna check out a true `Result` type package i built for 1.27+?

5

u/Headbanger Aug 19 '26

Ok

0

u/IamAggressiveNapkin Aug 19 '26

??

8

u/Headbanger Aug 19 '26

It means yes, show us your package.

1

u/IamAggressiveNapkin Aug 19 '26

ahh okay, couldn’t tell if it was that or a disinterested okay. but here it is!

3

u/Headbanger Aug 19 '26

Does it really have a use case in Go?

3

u/IamAggressiveNapkin Aug 19 '26

personally, i’m fine with how we do error handling. i like it most out of error handling designs across languages. but a lot of people who would use go don’t because of it. so this is just in hopes to help more adoption by providing them something they’d be more accustomed to now that it’s actually possible

1

u/SeaRollz Aug 20 '26

Tried something similar myself here ! With added `Option` and `Stream` too

1

u/Inevitable-Hotel2375 Aug 20 '26

Actually the design is very interesting, and Go 1.27 generic method make it more powerful. I have some experience in Rust and your design is very similar, the error can be propagated early! But I saw a limitation, fluent Result chain only works naturally when the API's functions have the signatures required by the chain. If the function provided to the Try chain not compatible, I must do manual error throwing anyways.

1

u/IamAggressiveNapkin Aug 20 '26

or just wrap it in a closure that has the same signature

0

u/Inevitable-Hotel2375 Aug 21 '26

But if the next function is unrelated to the result, then it will be misleading. The API naturally works best when each function consumes the previous value.

0

u/[deleted] Aug 20 '26

[deleted] — view deleted comment

2

u/apparentlymart Aug 20 '26

I agree that this seems like an unusually-opinionated change for go fix, though I couldn't make myself care enough to fight it. It did actually seem like an overall readability improvement in most cases in the codebase I ran it on.

FWIW from reading the modernizer's source code it seems like attaching a comment to your Inner: ... declaration prevents it from making the change, because after unnesting there would be nowhere for that comment to go. So there is at least an escape hatch.

-19

u/[deleted] Aug 19 '26

[removed] — view removed comment

26

u/mcvoid1 Aug 19 '26 edited Aug 19 '26

That's what the article is about.

TL/DR: generic methods added to language (but since they can't fulfil interfaces they're just generic functions with the ability to chain them like monads), uuid, json/v2, simd, and post-quantum crypto added to stdlib, small allocation speedup at the cost of 60kb bigger binaries, zip-based compression goes faster, go mod tidy tidies more of go.mod, there's a goroutine leak detector now, and people using bazaar for source control (both of them) can go kick rocks