Add lang handling

This commit is contained in:
Eliot Whalan 2016-06-23 13:19:50 +10:00
parent 825f6e5273
commit 83cc8f9921
No known key found for this signature in database
GPG Key ID: C0A42175139840D6
1 changed files with 8 additions and 5 deletions

11
main.go
View File

@ -76,7 +76,7 @@ func hash(paste string) string {
return sha return sha
} }
func save(raw string) []string { func save(raw string, lang string) []string {
db, err := sql.Open("mysql", DATABASE) db, err := sql.Open("mysql", DATABASE)
check(err) check(err)
@ -92,7 +92,11 @@ func save(raw string) []string {
} }
} }
id := generateName() id := generateName()
if lang == "" {
url := ADDRESS + "/p/" + id url := ADDRESS + "/p/" + id
} else {
url := ADDRESS + "/p/" + id + "/" lang
}
delKey := uniuri.NewLen(40) delKey := uniuri.NewLen(40)
paste := html.EscapeString(raw) paste := html.EscapeString(raw)
@ -102,7 +106,6 @@ func save(raw string) []string {
check(err) check(err)
db.Close() db.Close()
return []string{id, sha, url, paste, delKey} return []string{id, sha, url, paste, delKey}
} }
func delHandler(w http.ResponseWriter, r *http.Request) { func delHandler(w http.ResponseWriter, r *http.Request) {
@ -133,11 +136,11 @@ func saveHandler(w http.ResponseWriter, r *http.Request) {
switch r.Method { switch r.Method {
case "POST": case "POST":
paste := r.FormValue("p") paste := r.FormValue("p")
lang := r.FormValue("lang")
if paste == "" { if paste == "" {
http.Error(w, "Empty paste", 500) http.Error(w, "Empty paste", 500)
} }
values := save(paste, lang)
values := save(paste)
b := &Response{ b := &Response{
ID: values[0], ID: values[0],
HASH: values[1], HASH: values[1],