Adding MustGenerate, GenerateOnce, and MustGenerateOnce.
These are largely just convenience functions/wrappers.
This commit is contained in:
parent
b12131b661
commit
cb35a91855
@ -46,6 +46,49 @@ func (o *GenOpts) Generate() (passwords []string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// MustGenerate is like Generate, but will panic on error instead of returning.
|
||||
func (o *GenOpts) MustGenerate() (passwords []string) {
|
||||
|
||||
var err error
|
||||
|
||||
if passwords, err = o.Generate(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
GenOnce generates a *single* password from a GenOpts.
|
||||
|
||||
This method is particularly useful/convenient if GenOpts.Count is 1
|
||||
and you don't want to have to assign to a slice and then get the first index.
|
||||
*/
|
||||
func (o GenOpts) GenerateOnce() (password string, err error) {
|
||||
|
||||
var passwds []string
|
||||
|
||||
o.Count = 1
|
||||
if passwds, err = o.Generate(); err != nil {
|
||||
return
|
||||
}
|
||||
password = passwds[0]
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// MustGenerateOnce is like GenerateOnce, but will panic on error instead of returning.
|
||||
func (o *GenOpts) MustGenerateOnce() (password string) {
|
||||
|
||||
var err error
|
||||
|
||||
if password, err = o.GenerateOnce(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
GenerateCollection returns a PwCollection instead of a slice of password text.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user