1
0
mirror of https://github.com/google/uuid.git synced 2025-09-16 09:16:30 +02:00

add MustParse(), which returns an UUID or panics

This commit is contained in:
Martin Lindhe
2017-11-22 06:20:00 +01:00
parent 8c31c18f31
commit 3d673cf3cf

10
uuid.go
View File

@@ -97,6 +97,16 @@ func ParseBytes(b []byte) (UUID, error) {
return uuid, nil
}
// MustParse is like Parse but panics if the string cannot be parsed.
// It simplifies safe initialization of global variables holding compiled UUIDs.
func MustParse(s string) UUID {
uuid, err := Parse(s)
if err != nil {
panic(`uuid: Parse(` + s + `): ` + err.Error())
}
return uuid
}
// FromBytes creates a new UUID from a byte slice. Returns an error if the slice
// does not have a length of 16. The bytes are copied from the slice.
func FromBytes(b []byte) (uuid UUID, err error) {