Updated README.md and added code-example for programmatic use

This commit is contained in:
Winni Neessen 2021-09-23 19:20:17 +02:00
parent 6047e79e0c
commit da4a9b1040
3 changed files with 39 additions and 3 deletions

View file

@ -4,9 +4,9 @@
<option name="autoReloadType" value="ALL" /> <option name="autoReloadType" value="ALL" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="e32960c0-29e5-4669-9fc2-ef12314486ce" name="Changes" comment="More README.md updates"> <list default="true" id="e32960c0-29e5-4669-9fc2-ef12314486ce" name="Changes" comment="Updated CLI usage text to reflect the changes of #27">
<change afterPath="$PROJECT_DIR$/example-code/simple-password-generator/main.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cmd/apg/apg.go" beforeDir="false" afterPath="$PROJECT_DIR$/cmd/apg/apg.go" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -86,7 +86,8 @@
<MESSAGE value="Minor code cleanups and updated README to reflect #27" /> <MESSAGE value="Minor code cleanups and updated README to reflect #27" />
<MESSAGE value="README.md updated" /> <MESSAGE value="README.md updated" />
<MESSAGE value="More README.md updates" /> <MESSAGE value="More README.md updates" />
<option name="LAST_COMMIT_MESSAGE" value="More README.md updates" /> <MESSAGE value="Updated CLI usage text to reflect the changes of #27" />
<option name="LAST_COMMIT_MESSAGE" value="Updated CLI usage text to reflect the changes of #27" />
</component> </component>
<component name="VgoProject"> <component name="VgoProject">
<integration-enabled>true</integration-enabled> <integration-enabled>true</integration-enabled>

View file

@ -88,6 +88,14 @@ It is recommed to install apg in a directory of your ```$PATH``` environment. To
```sh ```sh
$ sudo cp apg /usr/local/bin/apg $ sudo cp apg /usr/local/bin/apg
``` ```
## Programmatic interface
Since v0.4.0 the CLI and the main package functionality have been separated from each other, which makes
it easier to use the `apg-go` package in other Go code as well. This way you can make of the password
generation in your own code without having to rely on the actual apg-go binary.
Code examples on how to use the package can be found in the [example-code](example-code) directory.
## Usage examples ## Usage examples
### Default behaviour ### Default behaviour
By default apg-go will generate 6 passwords, with a minimum length of 12 characters and a By default apg-go will generate 6 passwords, with a minimum length of 12 characters and a

View file

@ -0,0 +1,27 @@
package main
import (
"fmt"
"github.com/wneessen/apg-go/chars"
"github.com/wneessen/apg-go/config"
"github.com/wneessen/apg-go/random"
)
func main() {
c := config.Config{
UseNumber: true,
UseSpecial: true,
UseUpperCase: true,
UseLowerCase: true,
PwAlgo: 1,
MinPassLen: 15,
MaxPassLen: 15,
}
pl := config.GetPwLengthFromParams(&c)
cs := chars.GetRange(&c)
pw, err := random.GetChar(&cs, pl)
if err != nil {
panic(err)
}
fmt.Println("Your Password:", pw)
}