1
0
mirror of https://github.com/google/uuid.git synced 2024-11-28 08:49:08 +02:00

replace Must* funcs with a single generic Must func

The MustParse and MustNewUUID functions have been removed since they
can be replaced simply using the new function.

    uuid.Must(uuid.Parse(s))
    uuid.Must(uuid.NewUUID())

This also fixes a spurious bug in the UnmarshalJSON method that
prevented compiling the json.go file.
This commit is contained in:
Bryan Matsuo 2016-02-24 11:34:15 -08:00
parent a8b7006b7b
commit 7dd4798941
6 changed files with 11 additions and 21 deletions

View File

@ -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
)

View File

@ -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 {

View File

@ -42,7 +42,7 @@ func TestClockSeqRace(t *testing.T) {
select {
case <-done:
return
case ch <- MustNewUUID():
case ch <- Must(NewUUID()):
}
}
}()

View File

@ -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")

View File

@ -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

View File

@ -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
}