1
0
mirror of https://github.com/google/uuid.git synced 2025-02-18 12:24:00 +02:00

Merge pull request #26 from martinlindhe/mustparse

add MustParse(), which returns an UUID or panics
This commit is contained in:
pborman 2018-08-28 13:14:23 -05:00 committed by GitHub
commit 7cf75050e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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