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,16 +84,19 @@ 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 {
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)