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
|
return err
|
||||||
})
|
})
|
||||||
err = db.Update(func(tx *bolt.Tx) error {
|
// Add the new name to the programdata so its not randomly generated
|
||||||
b := tx.Bucket([]byte("programdata"))
|
if err == nil {
|
||||||
id, _ := b.NextSequence()
|
err2 := db.Update(func(tx *bolt.Tx) error {
|
||||||
idInt := int(id)
|
b := tx.Bucket([]byte("programdata"))
|
||||||
return b.Put(itob(idInt), []byte(p.Title))
|
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
|
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) {
|
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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user