web: don't run translation on empty text

This was causing an error when submitting nothing.
This commit is contained in:
Alexey Yerin 2021-05-10 17:01:47 +03:00
parent 77b101f877
commit 56459bf680
1 changed files with 5 additions and 0 deletions

5
web.go
View File

@ -24,6 +24,11 @@ func CreateWebHandler(tmpl *template.Template, settings *TranslateSettings) func
to := req.FormValue("to")
text := req.FormValue("text")
if text == "" {
tmpl.ExecuteTemplate(w, "index", indexPageData{Languages, from, to, text, ""})
return
}
translation, err := Translate(settings, from, to, text)
if err != nil {
writeError(w, 500, err)