Add lang handling
This commit is contained in:
parent
ad4ada443e
commit
2b6d33bda0
11
main.go
11
main.go
|
@ -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],
|
||||||
|
|
Loading…
Reference in New Issue