Skip to content

Instantly share code, notes, and snippets.

@p4tin
Last active December 13, 2015 18:34
Show Gist options
  • Save p4tin/cfbdf6999c93ce93905e to your computer and use it in GitHub Desktop.
Save p4tin/cfbdf6999c93ce93905e to your computer and use it in GitHub Desktop.
Golang Generate Passwords
package main
import (
"fmt"
"strings"
"bytes"
"github.com/Pallinder/go-randomdata"
)
func main() {
for i:=1; i<=10;i++ {
fmt.Printf("%03d - %s%s%d\n", i, MakeFirstUpperCase(randomdata.Adjective()),
MakeFirstUpperCase(randomdata.Noun()),
randomdata.Number(100,999))
}
}
func MakeFirstUpperCase(s string) string {
if len(s) < 2 {
return strings.ToLower(s)
}
bts := []byte(s)
lc := bytes.ToUpper([]byte{bts[0]})
rest := bts[1:]
return string(bytes.Join([][]byte{lc, rest}, nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment