Skip to content

Add NewV7WithTime, NewV8 and typed length errors - #1

Open
jai-deepsource wants to merge 1 commit into
masterfrom
feat/v7-custom-time-v8-and-error-cleanup
Open

jai-deepsource wants to merge 1 commit into
masterfrom
feat/v7-custom-time-v8-and-error-cleanup

Conversation

@jai-deepsource

Copy link
Copy Markdown

What

Adds NewV7WithTime and RFC 9562 version 8 UUIDs. Adds typed length errors that work with errors.Is. Fixes two data races. Splits uuid.go into smaller files.

Changes

New API

  • NewV7WithTime(t) builds a v7 UUID from an existing creation time, for example to backfill records. It stays out of the NewV7 monotonic sequence.
  • NewV8(data) and NewV8FromBytes(b) build custom UUIDs.
  • UUID.Timestamp, IsNil, IsMax, AppendText and AppendBinary.

Errors

  • Binary length errors match ErrInvalidLength.
  • Scan wraps parse errors with %w.
  • NullUUID text and binary decoding round trips the invalid value.

Concurrency

  • NewV6WithTime now holds timeMu while it calls getTime.
  • EnableRandPool and DisableRandPool can be called concurrently.

Cleanup

  • Errors move to errors.go and the rand pool moves to rand.go.
  • Parse, ParseBytes and Validate share one hex decoder.
  • Node ID selection skips down and loopback interfaces.
  • Build tags use go:build, and go.mod sets go 1.19.
  • CI runs vet, race tests and gofmt.

Testing

  • go test -race ./...
  • v7 tests move to version7_test.go. New tests cover v8, NewV7WithTime, the NullUUID round trip, and the errors.Is behaviour.

- Add NewV7WithTime for backfilling records with an existing creation time, kept out of the NewV7 monotonic sequence
- Add NewV8 and NewV8FromBytes for RFC 9562 custom UUIDs
- Add UUID.Timestamp, IsNil, IsMax, AppendText and AppendBinary
- Binary length errors now match ErrInvalidLength and Scan wraps parse errors with %w so errors.Is works through them
- NullUUID text and binary decoding now round trip the invalid value
- Fix data race in NewV6WithTime, which called getTime without holding timeMu
- Make EnableRandPool and DisableRandPool safe to call concurrently
- Move errors and rand pool code into errors.go and rand.go, share hex decoding between Parse, ParseBytes and Validate
- Skip down and loopback interfaces when picking a node ID
- Switch to go:build tags, set go 1.19 in go.mod, run vet, race and gofmt in CI
- Move v7 tests into version7_test.go and add tests for the new behaviour
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant