From b162e2af2b4d4d9c3e49cb91aed61e28ba498a69 Mon Sep 17 00:00:00 2001 From: Cole MacKenzie Date: Sun, 27 Oct 2024 19:53:55 -0700 Subject: [PATCH] fix: replace rfc4122 with rfc9562 --- .github/.dependabot.yml | 4 ++-- .github/workflows/go.yml | 23 +++++++++++------------ LICENSE.md | 2 +- README.md | 12 ++++++------ encoding_test.go | 6 ++++++ uuid.go | 8 ++++---- uuid_test.go | 7 +++++++ 7 files changed, 37 insertions(+), 25 deletions(-) diff --git a/.github/.dependabot.yml b/.github/.dependabot.yml index ab904b9..aa84cd3 100644 --- a/.github/.dependabot.yml +++ b/.github/.dependabot.yml @@ -9,8 +9,8 @@ updates: directory: "/" schedule: interval: "weekly" - - - package-ecosystem: "github-actions" + + - package-ecosystem: "github-actions" directory: ".github/workflows" schedule: interval: "weekly" diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 3e9a76d..61b52da 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -5,24 +5,23 @@ name: Go on: push: - branches: [ "main" ] + branches: ["main"] pull_request: - branches: [ "main" ] + branches: ["main"] jobs: - build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v3 - - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version: 1.19 + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.23 - - name: Build - run: go build -v ./... + - name: Build + run: go build -v ./... - - name: Test - run: go test -v ./... + - name: Test + run: go test -v ./... diff --git a/LICENSE.md b/LICENSE.md index 5eecc9e..5dcdc4a 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SOFTWARE. diff --git a/README.md b/README.md index cde53e4..efbf5a3 100644 --- a/README.md +++ b/README.md @@ -13,10 +13,10 @@ go get github.com/cmackenzie1/go-uuid ## Supported versions -| Version | Variant | Details | -|-------------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `Version 4` | `10` | Pure random as defined in [RFC4122](https://www.rfc-editor.org/rfc/rfc4122). | -| `Version 7` | `10` | Time-sortable as defined in a [working draft]( https://www.ietf.org/archive/id/draft-ietf-uuidrev-rfc4122bis-01.html#name-uuid-version-7) meant to update [RFC4122](https://www.rfc-editor.org/rfc/rfc4122). | +| Version | Variant | Details | +| ----------- | ------- | ----------------------------------------------------------------------------------- | +| `Version 4` | `10` | Pure random as defined in [RFC9562](https://www.rfc-editor.org/rfc/rfc9562.html). | +| `Version 7` | `10` | Time-sortable as defined in [RFC9562](https://www.rfc-editor.org/rfc/rfc9562.html). | ## Usage @@ -53,7 +53,7 @@ func main() { - A single library with no external dependencies for multiple types of UUIDs. - `UUID` type is defined as a fixed-size, `[16]byte`, array which can be used as a map (instead of the 36 byte string representation). Over 2x space savings for memory! -- Limited API. As per RFC4122, UUIDs (while containing embedded information), should be treated as opaque +- Limited API. As per RFC9562, UUIDs (while containing embedded information), should be treated as opaque values. There is no temptation to build dependencies on the embedded information if you can't easily access it. 😉 ### When should I use UUIDv7 over UUIDv4? @@ -77,4 +77,4 @@ Please make sure to update tests as appropriate. [MIT](./LICENSE.md) -[1]: https://www.ietf.org/archive/id/draft-ietf-uuidrev-rfc4122bis-01.html#section-2.1 \ No newline at end of file +[1]: https://www.ietf.org/archive/id/draft-ietf-uuidrev-rfc4122bis-01.html#section-2.1 diff --git a/encoding_test.go b/encoding_test.go index 76c35d9..2816a3b 100644 --- a/encoding_test.go +++ b/encoding_test.go @@ -72,6 +72,12 @@ func TestNewV4_UnmarshalJSON(t *testing.T) { return exampleJSON{ID: uuid.Nil} }, }, + "null": { + uuid: "{\"id\":null}", + want: func() exampleJSON { + return exampleJSON{ID: uuid.Nil} + }, + }, } for name, tt := range tests { diff --git a/uuid.go b/uuid.go index 87306f5..1404ced 100644 --- a/uuid.go +++ b/uuid.go @@ -18,13 +18,13 @@ var ( errUnsupportedVariant = errors.New("unsupported variant") ) -// UUID is a 128 bit (16 byte) value defined by RFC4122. +// UUID is a 128 bit (16 byte) value defined by RFC9562. type UUID [16]byte // Nil represents the zero-value UUID var Nil UUID -// NewV4 returns a UUID Version 4 as defined in RFC4122. Random bits +// NewV4 returns a UUID Version 4 as defined in RFC9562. Random bits // are generated using crypto/rand. // // 0 1 2 3 @@ -53,11 +53,11 @@ func NewV4() (UUID, error) { return uuid, nil } -// NewV7 returns a UUID Version 7 as defined in the drafted revision for RFC4122. +// NewV7 returns a UUID Version 7 as defined in the drafted revision for RFC9562. // Random bits are generated using crypto/rand. // Due to millisecond resolution of the timestamp, UUIDs generated during the // same millisecond will sort arbitrarily. -// https://www.ietf.org/archive/id/draft-ietf-uuidrev-rfc4122bis-01.html#name-uuid-version-7 +// https://www.rfc-editor.org/rfc/rfc9562.html#name-uuid-version-7 // // 0 1 2 3 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 diff --git a/uuid_test.go b/uuid_test.go index f7d2adb..d7d3a93 100644 --- a/uuid_test.go +++ b/uuid_test.go @@ -109,3 +109,10 @@ func TestPrint(t *testing.T) { u, _ = NewV7() t.Logf("v7: %s %v", u, u[:]) } + +func BenchmarkNewV4(b *testing.B) { + for i := 0; i < b.N; i++ { + a, _ := NewV4() + _ = a // prevent compiler optimization + } +}