Last active
December 13, 2015 18:34
-
-
Save p4tin/cfbdf6999c93ce93905e to your computer and use it in GitHub Desktop.
Golang Generate Passwords
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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