Skip to content
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

Creates a virtual package at v3 subdirectory. #66

Closed
wants to merge 5 commits into from
Closed
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: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
language: go
sudo: false
go:
- 1.7
- 1.8
- 1.9
- "1.10"
- 1.11
Expand All @@ -16,7 +14,7 @@ env:
before_install:
- go get golang.org/x/tools/cmd/cover
script:
- go test ./... -race -coverprofile=coverage.txt -covermode=atomic
- go test . -race -coverprofile=coverage.txt -covermode=atomic
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a thought, but is it worth expanding the tests to include an explicit test of the behaviour you're expecting a user to see, with respect to import paths? That suite of tests might also include your expectations on GOPATH vs module mode in Go 1.11.

after_success:
- bash <(curl -s https://codecov.io/bash)
notifications:
Expand Down
183 changes: 183 additions & 0 deletions v3/forward.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
// Copyright (c) 2018 Andrei Tudor Călin <mail@acln.ro>
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, 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.

package uuid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should leave a note here, for godoc purposes. The note should say that this uuid package consists of forwarding declarations only, and that callers should look at the root godoc (godoc.org/github.com/gofrs/uuid) instead.


import (
"github.com/gofrs/uuid"
)

// Size of a UUID in bytes.
const Size = uuid.Size

// UUID is an array type to represent the value of a UUID, as defined in RFC-4122.
type UUID = uuid.UUID

// UUID versions.
const (
V1 = uuid.V1 // Version 1 (date-time and MAC address)
V2 = uuid.V2 // Version 2 (date-time and MAC address, DCE security version)
V3 = uuid.V3 // Version 3 (namespace name-based)
V4 = uuid.V4 // Version 4 (random)
V5 = uuid.V5 // Version 5 (namespace name-based)
)

// UUID layout variants.
const (
VariantNCS = uuid.VariantNCS
VariantRFC4122 = uuid.VariantRFC4122
VariantMicrosoft = uuid.VariantMicrosoft
VariantFuture = uuid.VariantFuture
)

// UUID DCE domains.
const (
DomainPerson = uuid.DomainPerson
DomainGroup = uuid.DomainGroup
DomainOrg = uuid.DomainOrg
)

// Timestamp is the count of 100-nanosecond intervals since 00:00:00.00,
// 15 October 1582 within a V1 UUID. This type has no meaning for V2-V5
// UUIDs since they don't have an embedded timestamp.
type Timestamp = uuid.Timestamp

// TimestampFromV1 returns the Timestamp embedded within a V1 UUID.
// Returns an error if the UUID is any version other than 1.
func TimestampFromV1(u UUID) (Timestamp, error) {
return uuid.TimestampFromV1(u)
}

// Nil is the nil UUID, as specified in RFC-4122, that has all 128 bits set to
// zero.
var Nil = uuid.Nil

// Predefined namespace UUIDs.
var (
NamespaceDNS = uuid.NamespaceDNS
NamespaceURL = uuid.NamespaceURL
NamespaceOID = uuid.NamespaceOID
NamespaceX500 = uuid.NamespaceX500
)

// Must is a helper that wraps a call to a function returning (UUID, error)
// and panics if the error is non-nil. It is intended for use in variable
// initializations such as
// var packageUUID = v3.Must(v3.FromString("123e4567-e89b-12d3-a456-426655440000"))
func Must(u UUID, err error) UUID {
return uuid.Must(u, err)
}

// NullUUID can be used with the standard sql package to represent a
// UUID value that can be NULL in the database.
type NullUUID = uuid.NullUUID

// HWAddrFunc is the function type used to provide hardware (MAC) addresses.
type HWAddrFunc = uuid.HWAddrFunc

// Generator provides an interface for generating UUIDs.
type Generator = uuid.Generator

// DefaultGenerator is the default UUID Generator used by this package.
var DefaultGenerator = uuid.DefaultGenerator

// NewV1 returns a UUID based on the current timestamp and MAC address.
func NewV1() (UUID, error) {
return uuid.NewV1()
}

// NewV2 returns a DCE Security UUID based on the POSIX UID/GID.
func NewV2(domain byte) (UUID, error) {
return uuid.NewV2(domain)
}

// NewV3 returns a UUID based on the MD5 hash of the namespace UUID and name.
func NewV3(ns UUID, name string) UUID {
return uuid.NewV3(ns, name)
}

// NewV4 returns a randomly generated UUID.
func NewV4() (UUID, error) {
return uuid.NewV4()
}

// NewV5 returns a UUID based on SHA-1 hash of the namespace UUID and name.
func NewV5(ns UUID, name string) UUID {
return uuid.NewV5(ns, name)
}

// Gen is a reference UUID generator based on the specifications laid out in
// RFC-4122 and DCE 1.1: Authentication and Security Services. This type
// satisfies the Generator interface as defined in this package.
//
// For consumers who are generating V1 UUIDs, but don't want to expose the MAC
// address of the node generating the UUIDs, the NewGenWithHWAF() function has been
// provided as a convenience. See the function's documentation for more info.
//
// The authors of this package do not feel that the majority of users will need
// to obfuscate their MAC address, and so we recommend using NewGen() to create
// a new generator.
type Gen = uuid.Gen

// NewGen returns a new instance of Gen with some default values set. Most
// people should use this.
func NewGen() *Gen {
return uuid.NewGen()
}

// NewGenWithHWAF builds a new UUID generator with the HWAddrFunc provided. Most
// consumers should use NewGen() instead.
//
// This is used so that consumers can generate their own MAC addresses, for use
// in the generated UUIDs, if there is some concern about exposing the physical
// address of the machine generating the UUID.
//
// The Gen generator will only invoke the HWAddrFunc once, and cache that MAC
// address for all the future UUIDs generated by it. If you'd like to switch the
// MAC address being used, you'll need to create a new generator using this
// function.
func NewGenWithHWAF(hwaf HWAddrFunc) *Gen {
return uuid.NewGenWithHWAF(hwaf)
}

// FromBytes returns a UUID generated from the raw byte slice input.
// It will return an error if the slice isn't 16 bytes long.
func FromBytes(input []byte) (UUID, error) {
return uuid.FromBytes(input)
}

// FromBytesOrNil returns a UUID generated from the raw byte slice input.
// Same behavior as FromBytes(), but returns v3.Nil instead of an error.
func FromBytesOrNil(input []byte) UUID {
return uuid.FromBytesOrNil(input)
}

// FromString returns a UUID parsed from the input string.
// Input is expected in a form accepted by UnmarshalText.
func FromString(input string) (UUID, error) {
return uuid.FromString(input)
}

// FromStringOrNil returns a UUID parsed from the input string.
// Same behavior as FromString(), but returns v3.Nil instead of an error.
func FromStringOrNil(input string) UUID {
return uuid.FromStringOrNil(input)
}
1 change: 1 addition & 0 deletions v3/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module github.com/gofrs/uuid/v3