From 81e23c04363953668c432d2b205d54ece32f13a0 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Tue, 25 Apr 2023 17:54:20 +0200 Subject: [PATCH] feat: add MustGenerate overload --- pwgen.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pwgen.go b/pwgen.go index a7321c0..48ebbba 100644 --- a/pwgen.go +++ b/pwgen.go @@ -18,6 +18,14 @@ func Generate(opts ...GenerationOption) (string, error) { return Default.Generate(opts...) } +func MustGenerate(opts ...GenerationOption) string { + if pw, err := Generate(opts...); err != nil { + panic(err) + } else { + return pw + } +} + func NewDefaultGenerator(prng Int32n) DefaultGenerator { if prng == nil { prng = rand.New(rand.NewSource(time.Now().UnixNano()))