Skip to content

Commit

Permalink
feat: Add Must functions
Browse files Browse the repository at this point in the history
Add MustGenerate and MustID functions that panic on error instead
of returning it.

Fixes: #17
  • Loading branch information
matoous committed Oct 8, 2020
1 parent 53c5d4a commit 554e6f8
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions gonanoid.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,21 @@ func Nanoid(param ...int) (string, error) {
func ID(l int) (string, error) {
return Nanoid(l)
}

// MustID is the same as ID but panics on error.
func MustID(l int) string {
id, err := Nanoid(l)
if err != nil {
panic(err)
}
return id
}

// MustGenerate is the same as Generate but panics on error.
func MustGenerate(rawAlphabet string, size int) string {
id, err := Generate(rawAlphabet, size)
if err != nil {
panic(err)
}
return id
}

0 comments on commit 554e6f8

Please sign in to comment.