aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--uuid.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/uuid.go b/uuid.go
index 7f3643f..b8d756d 100644
--- a/uuid.go
+++ b/uuid.go
@@ -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) {