Let mysql to more searching
This commit is contained in:
parent
3c4a9e0032
commit
62453be692
13
main.go
13
main.go
|
@ -56,24 +56,19 @@ func check(err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateName() string {
|
func generateName() string {
|
||||||
s := uniuri.NewLen(LENGTH)
|
id := uniuri.NewLen(LENGTH)
|
||||||
db, err := sql.Open("mysql", DATABASE)
|
db, err := sql.Open("mysql", DATABASE)
|
||||||
check(err)
|
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() {
|
for query.Next() {
|
||||||
var id string
|
|
||||||
err := query.Scan(&id)
|
|
||||||
if err != nil {
|
|
||||||
|
|
||||||
}
|
|
||||||
if id == s {
|
|
||||||
generateName()
|
generateName()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
db.Close()
|
db.Close()
|
||||||
|
|
||||||
return s
|
return id
|
||||||
|
|
||||||
}
|
}
|
||||||
func hash(paste string) string {
|
func hash(paste string) string {
|
||||||
|
|
Loading…
Reference in New Issue