mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
Updated
This commit is contained in:
parent
64eed783af
commit
7e3423c12e
18
db.go
18
db.go
@ -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
3
utils.go
3
utils.go
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user