diff --git a/hash.go b/hash.go index 56db407..1e3ca79 100644 --- a/hash.go +++ b/hash.go @@ -12,10 +12,10 @@ import ( // 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 @@ import ( "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 @@ func TestClockSeqRace(t *testing.T) { 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 @@ func TestScan(t *testing.T) { 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 TestScan(t *testing.T) { 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 @@ func ParseBytes(b []byte) (UUID, error) { 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 @@ func NewUUID() (UUID, error) { 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 -}