Let mysql to more searching

This commit is contained in:
Eliot Whalan 2016-06-26 21:16:14 +10:00
parent 3c4a9e0032
commit 62453be692
No known key found for this signature in database
GPG Key ID: C0A42175139840D6
1 changed files with 5 additions and 10 deletions

13
main.go
View File

@ -56,24 +56,19 @@ func check(err error) {
}
func generateName() string {
s := uniuri.NewLen(LENGTH)
id := uniuri.NewLen(LENGTH)
db, err := sql.Open("mysql", DATABASE)
check(err)
query, err := db.Query("select id from pastebin")
query, err := db.Query("select id from pastebin where id=?", id)
if err != sql.ErrNoRows {
for query.Next() {
var id string
err := query.Scan(&id)
if err != nil {
}
if id == s {
generateName()
}
}
db.Close()
return s
return id
}
func hash(paste string) string {