1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00
This commit is contained in:
Zack Scholl 2016-02-14 09:14:01 -05:00
parent 64eed783af
commit 7e3423c12e
3 changed files with 15 additions and 1864 deletions

8
db.go
View File

@ -179,12 +179,18 @@ func (p *WikiData) save(newText string) error {
} }
return err return err
}) })
err = db.Update(func(tx *bolt.Tx) error { // Add the new name to the programdata so its not randomly generated
if err == nil {
err2 := db.Update(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte("programdata")) b := tx.Bucket([]byte("programdata"))
id, _ := b.NextSequence() id, _ := b.NextSequence()
idInt := int(id) idInt := int(id)
return b.Put(itob(idInt), []byte(p.Title)) return b.Put(itob(idInt), []byte(p.Title))
}) })
if err2 != nil {
return fmt.Errorf("could not add to programdata: %s", err)
}
}
return err return err
} }

File diff suppressed because it is too large Load Diff

View File

@ -44,6 +44,7 @@ func randomAdjective() string {
func randomAlliterateCombo() (combo string) { func randomAlliterateCombo() (combo string) {
combo = "" combo = ""
// first determine which names are taken from program data
takenNames := []string{} takenNames := []string{}
err := db.View(func(tx *bolt.Tx) error { err := db.View(func(tx *bolt.Tx) error {
// Assume bucket exists and has keys // Assume bucket exists and has keys
@ -57,6 +58,7 @@ func randomAlliterateCombo() (combo string) {
if err != nil { if err != nil {
panic(err) panic(err)
} }
// generate random alliteration thats not been used
for { for {
animal := randomAnimal() animal := randomAnimal()
adjective := randomAdjective() adjective := randomAdjective()
@ -68,6 +70,7 @@ func randomAlliterateCombo() (combo string) {
return return
} }
// is there a string in a slice?
func stringInSlice(s string, strings []string) bool { func stringInSlice(s string, strings []string) bool {
for _, k := range strings { for _, k := range strings {
if s == k { if s == k {