Save function return response struct
This commit is contained in:
parent
d87b462b1d
commit
cf42af990a
17
main.go
17
main.go
|
@ -98,7 +98,8 @@ func durationFromExpiry(expiry string) time.Duration {
|
||||||
return time.Hour * 24 * (365 * 20)
|
return time.Hour * 24 * (365 * 20)
|
||||||
}
|
}
|
||||||
|
|
||||||
func save(raw string, lang string, title string, expiry string) []string {
|
func save(raw string, lang string, title string, expiry string) Response {
|
||||||
|
|
||||||
db, err := sql.Open("mysql", DATABASE)
|
db, err := sql.Open("mysql", DATABASE)
|
||||||
check(err)
|
check(err)
|
||||||
|
|
||||||
|
@ -110,7 +111,7 @@ func save(raw string, lang string, title string, expiry string) []string {
|
||||||
err := query.Scan(&id, &title, &hash, &paste, &delkey)
|
err := query.Scan(&id, &title, &hash, &paste, &delkey)
|
||||||
check(err)
|
check(err)
|
||||||
url := ADDRESS + "/p/" + id
|
url := ADDRESS + "/p/" + id
|
||||||
return []string{id, title, hash, url, paste, delkey}
|
return Response{id, title, hash, url, len(paste), delkey
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
id := generateName()
|
id := generateName()
|
||||||
|
@ -136,7 +137,7 @@ func save(raw string, lang string, title string, expiry string) []string {
|
||||||
check(err)
|
check(err)
|
||||||
}
|
}
|
||||||
db.Close()
|
db.Close()
|
||||||
return []string{id, title, sha, url, dataEscaped, delKey}
|
return Response{id, title, sha, url, len(dataEscaped), delKey}
|
||||||
}
|
}
|
||||||
|
|
||||||
func delHandler(w http.ResponseWriter, r *http.Request) {
|
func delHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -175,15 +176,7 @@ func saveHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Error(w, "Empty paste", 500)
|
http.Error(w, "Empty paste", 500)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
values := save(paste, lang, title, expiry)
|
b := save(paste, lang, title, expiry)
|
||||||
b := &Response{
|
|
||||||
ID: values[0],
|
|
||||||
TITLE: values[1],
|
|
||||||
HASH: values[2],
|
|
||||||
URL: values[3],
|
|
||||||
SIZE: len(values[4]),
|
|
||||||
DELKEY: values[5],
|
|
||||||
}
|
|
||||||
|
|
||||||
switch output {
|
switch output {
|
||||||
case "json":
|
case "json":
|
||||||
|
|
Loading…
Reference in New Issue