From 1b342f9976b62fdcb2c13d705cc6a437634e32d1 Mon Sep 17 00:00:00 2001 From: Eliot Whalan Date: Sun, 19 Jun 2016 16:27:54 +1000 Subject: [PATCH] Replace sqlite with mysql --- main.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index f1488cc..3172236 100644 --- a/main.go +++ b/main.go @@ -13,17 +13,23 @@ import ( "log" "net/http" + "database/sql" + "github.com/dchest/uniuri" "github.com/ewhal/pygments" + _ "github.com/go-sql-driver/mysql" "github.com/gorilla/mux" - _ "github.com/mattn/go-sqlite3" ) const ( - ADDRESS = "http://localhost:9900" - LENGTH = 6 - TEXT = "$ | curl -F 'p=<-' " + ADDRESS + "\n" - PORT = ":9900" + ADDRESS = "http://localhost:9900" + LENGTH = 6 + TEXT = "$ | curl -F 'p=<-' " + ADDRESS + "\n" + PORT = ":9900" + USERNAME = "" + PASS = "" + NAME = "" + DATABASE = USERNAME + ":" + PASS + "@/" + NAME + "?charset=utf8" ) type Response struct { @@ -42,7 +48,7 @@ func check(err error) { func generateName() string { s := uniuri.NewLen(LENGTH) - db, err := sql.Open("sqlite3", "./database.db") + db, err := sql.Open("mysql", DATABASE) check(err) query, err := db.Query("select id from pastebin") @@ -131,7 +137,8 @@ func saveHandler(w http.ResponseWriter, r *http.Request) { w.Write(x) default: - io.WriteString(w, values[2]+"\n") + io.WriteString(w, b.URL+"\n") + io.WriteString(w, "delete key: "+b.DELKEY+"\n") } }