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

18
db.go
View File

@ -179,12 +179,18 @@ func (p *WikiData) save(newText string) error {
}
return err
})
err = db.Update(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte("programdata"))
id, _ := b.NextSequence()
idInt := int(id)
return b.Put(itob(idInt), []byte(p.Title))
})
// 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"))
id, _ := b.NextSequence()
idInt := int(id)
return b.Put(itob(idInt), []byte(p.Title))
})
if err2 != nil {
return fmt.Errorf("could not add to programdata: %s", 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) {
combo = ""
// first determine which names are taken from program data
takenNames := []string{}
err := db.View(func(tx *bolt.Tx) error {
// Assume bucket exists and has keys
@ -57,6 +58,7 @@ func randomAlliterateCombo() (combo string) {
if err != nil {
panic(err)
}
// generate random alliteration thats not been used
for {
animal := randomAnimal()
adjective := randomAdjective()
@ -68,6 +70,7 @@ func randomAlliterateCombo() (combo string) {
return
}
// is there a string in a slice?
func stringInSlice(s string, strings []string) bool {
for _, k := range strings {
if s == k {