Merge pull request #6 from bmatsuo/bmatsuo/fix-file-perms
remove the spurious executable bit from go source files
diff --git a/hash.go b/hash.go
index 56db407..1e3ca79 100644
--- a/hash.go
+++ b/hash.go
@@ -12,10 +12,10 @@
// Well known namespace IDs and UUIDs
var (
- NameSpace_DNS = MustParse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
- NameSpace_URL = MustParse("6ba7b811-9dad-11d1-80b4-00c04fd430c8")
- NameSpace_OID = MustParse("6ba7b812-9dad-11d1-80b4-00c04fd430c8")
- NameSpace_X500 = MustParse("6ba7b814-9dad-11d1-80b4-00c04fd430c8")
+ NameSpace_DNS = Must(Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8"))
+ NameSpace_URL = Must(Parse("6ba7b811-9dad-11d1-80b4-00c04fd430c8"))
+ NameSpace_OID = Must(Parse("6ba7b812-9dad-11d1-80b4-00c04fd430c8"))
+ NameSpace_X500 = Must(Parse("6ba7b814-9dad-11d1-80b4-00c04fd430c8"))
NIL UUID // empty UUID, all zeros
)
diff --git a/json_test.go b/json_test.go
index 4140cee..245f91e 100644
--- a/json_test.go
+++ b/json_test.go
@@ -10,7 +10,7 @@
"testing"
)
-var testUUID = MustParse("f47ac10b-58cc-0372-8567-0e02b2c3d479")
+var testUUID = Must(Parse("f47ac10b-58cc-0372-8567-0e02b2c3d479"))
func TestJSON(t *testing.T) {
type S struct {
diff --git a/seq_test.go b/seq_test.go
index e340f9d..853a4aa 100644
--- a/seq_test.go
+++ b/seq_test.go
@@ -42,7 +42,7 @@
select {
case <-done:
return
- case ch <- MustNewUUID():
+ case ch <- Must(NewUUID()):
}
}
}()
diff --git a/sql_test.go b/sql_test.go
index d53d58c..c193196 100644
--- a/sql_test.go
+++ b/sql_test.go
@@ -15,7 +15,7 @@
var invalidTest string = "f47ac10b-58cc-0372-8567-0e02b2c3d4"
byteTest := make([]byte, 16)
- byteTestUUID := MustParse(stringTest)
+ byteTestUUID := Must(Parse(stringTest))
copy(byteTest, byteTestUUID[:])
// sunny day tests
@@ -94,7 +94,7 @@
func TestValue(t *testing.T) {
stringTest := "f47ac10b-58cc-0372-8567-0e02b2c3d479"
- uuid := MustParse(stringTest)
+ uuid := Must(Parse(stringTest))
val, _ := uuid.Value()
if val != stringTest {
t.Error("Value() did not return expected string")
diff --git a/uuid.go b/uuid.go
index 5fd83c0..18e71b1 100644
--- a/uuid.go
+++ b/uuid.go
@@ -77,12 +77,12 @@
return Parse(*(*string)(unsafe.Pointer(&b)))
}
-func MustParse(s string) UUID {
- u, err := Parse(s)
+// Must returns uuid if err is nil and panics otherwise.
+func Must(uuid UUID, err error) UUID {
if err != nil {
panic(err)
}
- return u
+ return uuid
}
// String returns the string form of uuid, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
diff --git a/version1.go b/version1.go
index 17c018a..6fe1cd2 100644
--- a/version1.go
+++ b/version1.go
@@ -42,13 +42,3 @@
return uuid, nil
}
-
-// MustNewUUID returns the Verison 1 UUID from calling NewUUID, or panics
-// if NewUUID fails.
-func MustNewUUID() UUID {
- uuid, err := NewUUID()
- if err != nil {
- panic(err)
- }
- return uuid
-}
diff --git a/version4.go b/version4.go
index 913d019..453cb95 100644
--- a/version4.go
+++ b/version4.go
@@ -4,7 +4,17 @@
package uuid
-// New returns a Random (Version 4) UUID or panics.
+import "io"
+
+// New is creates a new random UUID or panics. New is equivalent to
+// the expression
+//
+// uuid.Must(uuid.NewRandom())
+func New() UUID {
+ return Must(NewRandom())
+}
+
+// NewRandom returns a Random (Version 4) UUID or panics.
//
// The strength of the UUIDs is based on the strength of the crypto/rand
// package.
@@ -16,10 +26,13 @@
// means the probability is about 0.00000000006 (6 × 10−11),
// equivalent to the odds of creating a few tens of trillions of UUIDs in a
// year and having one duplicate.
-func New() UUID {
+func NewRandom() (UUID, error) {
var uuid UUID
- randomBits([]byte(uuid[:]))
+ _, err := io.ReadFull(rander, uuid[:])
+ if err != nil {
+ return NIL, err
+ }
uuid[6] = (uuid[6] & 0x0f) | 0x40 // Version 4
uuid[8] = (uuid[8] & 0x3f) | 0x80 // Variant is 10
- return uuid
+ return uuid, nil
}