uuid: `NewV7()` always generates a UUID with `7000` on browsers

1 min read Original article ↗

Go version

go version go1.27rc1 darwin/arm64

Output of go env in your module/workspace:

AR='ar'
CC='clang'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='clang++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN='/Users/hajimehoshi/go/bin'
GOCACHE='/Users/hajimehoshi/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/hajimehoshi/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/cj/73zbb35j0qx5t4b6rnqq0__h0000gn/T/go-build1757681747=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/hajimehoshi/test/uuidv7/go.mod'
GOMODCACHE='/Users/hajimehoshi/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPACKAGESDRIVER=''
GOPATH='/Users/hajimehoshi/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/hajimehoshi/sdk/go1.27rc1'
GOSUMDB='sum.golang.org'
GOTELEMETRY='on'
GOTELEMETRYDIR='/Users/hajimehoshi/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/hajimehoshi/sdk/go1.27rc1/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.27rc1'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

  1. Make this program
package main

import "uuid"

func main() {
	println(uuid.NewV7().String())
}
  1. Run this for js/wasm target (I tested GOOS=js GOARCH=wasm go1.27rc1 run main.go, which generates outputs to the console if you have node and go_js_wasm_exec in PATH)

What did you see happen?

The output always includ 7000 part

  • 019ee60f-29b3-7000-a12b-f817e25db8f4
  • 019ee610-29c7-7000-bc34-f04bc09150bb
  • 019ee610-2eb4-7000-884a-dfcad78e47d9

What did you expect to see?

The 000 part should include random bytes

(This issue was discovered by @mimifuwacc (https://x.com/mimifuwacc/status/2068357756609065444))