Fix up previous error

This commit is contained in:
Eliot Whalan 2016-08-10 19:11:48 +10:00
parent 7d9133008a
commit 9a0d625da4
1 changed files with 6 additions and 4 deletions

View File

@ -84,15 +84,18 @@ func Check(err error) {
// database // database
func GenerateName() string { func GenerateName() string {
// use uniuri to generate random string // use uniuri to generate random string
id := uniuri.NewLen(configuration.Length) // hardcode this for now until I figure out why json isn't parsing correctly
id := uniuri.NewLen(6)
db, err := sql.Open("mysql", DATABASE) db, err := sql.Open("mysql", DATABASE)
Check(err) Check(err)
defer db.Close() defer db.Close()
// query database if id exists and if it does call generateName again // query database if id exists and if it does call generateName again
_, err = db.Query("select id from pastebin where id=?", id) query, err = db.Query("select id from pastebin where id=?", id)
if err != sql.ErrNoRows { if err != sql.ErrNoRows {
GenerateName() for query.Next() {
GenerateName()
}
} }
return id return id
@ -390,7 +393,6 @@ func main() {
panic(err) panic(err)
} }
decoder := json.NewDecoder(file) decoder := json.NewDecoder(file)
configuration := Configuration{}
err = decoder.Decode(&configuration) err = decoder.Decode(&configuration)
if err != nil { if err != nil {
panic(err) panic(err)