From 9a0d625da456ea08b0ff6aa6d453d4b9d693c366 Mon Sep 17 00:00:00 2001 From: Eliot Whalan Date: Wed, 10 Aug 2016 19:11:48 +1000 Subject: [PATCH] Fix up previous error --- pastebin.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pastebin.go b/pastebin.go index 0d5d1c2..8dd305c 100644 --- a/pastebin.go +++ b/pastebin.go @@ -84,15 +84,18 @@ func Check(err error) { // database func GenerateName() 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) Check(err) defer db.Close() // 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 { - GenerateName() + for query.Next() { + GenerateName() + } } return id @@ -390,7 +393,6 @@ func main() { panic(err) } decoder := json.NewDecoder(file) - configuration := Configuration{} err = decoder.Decode(&configuration) if err != nil { panic(err)