Replace sqlite with mysql
This commit is contained in:
parent
84e7f7e95c
commit
cce40aa67c
13
main.go
13
main.go
|
@ -13,10 +13,12 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"database/sql"
|
||||||
|
|
||||||
"github.com/dchest/uniuri"
|
"github.com/dchest/uniuri"
|
||||||
"github.com/ewhal/pygments"
|
"github.com/ewhal/pygments"
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
_ "github.com/mattn/go-sqlite3"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -24,6 +26,10 @@ const (
|
||||||
LENGTH = 6
|
LENGTH = 6
|
||||||
TEXT = "$ <command> | curl -F 'p=<-' " + ADDRESS + "\n"
|
TEXT = "$ <command> | curl -F 'p=<-' " + ADDRESS + "\n"
|
||||||
PORT = ":9900"
|
PORT = ":9900"
|
||||||
|
USERNAME = ""
|
||||||
|
PASS = ""
|
||||||
|
NAME = ""
|
||||||
|
DATABASE = USERNAME + ":" + PASS + "@/" + NAME + "?charset=utf8"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Response struct {
|
type Response struct {
|
||||||
|
@ -42,7 +48,7 @@ func check(err error) {
|
||||||
|
|
||||||
func generateName() string {
|
func generateName() string {
|
||||||
s := uniuri.NewLen(LENGTH)
|
s := uniuri.NewLen(LENGTH)
|
||||||
db, err := sql.Open("sqlite3", "./database.db")
|
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")
|
||||||
|
@ -131,7 +137,8 @@ func saveHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Write(x)
|
w.Write(x)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
io.WriteString(w, values[2]+"\n")
|
io.WriteString(w, b.URL+"\n")
|
||||||
|
io.WriteString(w, "delete key: "+b.DELKEY+"\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue