Skip to content

fix: replace rfc4122 with rfc9562 #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/.dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ updates:
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "github-actions"

- package-ecosystem: "github-actions"
directory: ".github/workflows"
schedule:
interval: "weekly"
23 changes: 11 additions & 12 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
SOFTWARE.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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?
Expand All @@ -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
[1]: https://www.ietf.org/archive/id/draft-ietf-uuidrev-rfc4122bis-01.html#section-2.1
6 changes: 6 additions & 0 deletions encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions uuid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Loading