diff options
author | pborman <paul@borman.com> | 2018-08-28 13:14:23 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-28 13:14:23 -0500 |
commit | 7cf75050e9d999fdd02b7f4e46d90ce175bc9c4c (patch) | |
tree | 07f79e887cb02ecc797acde695a6dd95de22f02b | |
parent | d460ce9f8df2e77fb1ba55ca87fafed96c607494 (diff) | |
parent | 3d673cf3cf347691d8cc4a3cc65059d04aa7bc49 (diff) | |
download | google-uuid-7cf75050e9d999fdd02b7f4e46d90ce175bc9c4c.tar.gz |
Merge pull request #26 from martinlindhe/mustparse
add MustParse(), which returns an UUID or panics
-rw-r--r-- | uuid.go | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -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) { |