Add success message for uploads.
parent
5ea944695d
commit
0b02918dfb
12
main.go
12
main.go
|
@ -155,7 +155,7 @@ var baseHeader = `<!DOCTYPE html>
|
||||||
var baseFooter = `</body>
|
var baseFooter = `</body>
|
||||||
</html>`
|
</html>`
|
||||||
|
|
||||||
var uploadTemplate = `{{template "BaseHeader" "RUFF Upload Form"}}
|
var uploadTemplate = `{{template "BaseHeader" "RUFF - Upload Form"}}
|
||||||
<form enctype="multipart/form-data" action="/" method="post">
|
<form enctype="multipart/form-data" action="/" method="post">
|
||||||
<label for="file">Select a file for upload:</label>
|
<label for="file">Select a file for upload:</label>
|
||||||
<input type="file" name="file">
|
<input type="file" name="file">
|
||||||
|
@ -163,16 +163,21 @@ var uploadTemplate = `{{template "BaseHeader" "RUFF Upload Form"}}
|
||||||
</form>
|
</form>
|
||||||
{{template "BaseFooter"}}`
|
{{template "BaseFooter"}}`
|
||||||
|
|
||||||
var errorTemplate = `{{template "BaseHeader" "Upload Error"}}
|
var errorTemplate = `{{template "BaseHeader" "RUFF - Upload Error"}}
|
||||||
<p>{{.}}</p>
|
<p>{{.}}</p>
|
||||||
<p><a href="/">Go back</a></p>
|
<p><a href="/">Go back</a></p>
|
||||||
{{template "BaseFooter"}}`
|
{{template "BaseFooter"}}`
|
||||||
|
|
||||||
|
var messageTemplate = `{{template "BaseHeader" (print "RUFF - " .)}}
|
||||||
|
<p>{{.}}</p>
|
||||||
|
{{template "BaseFooter"}}`
|
||||||
|
|
||||||
func setupUpload(server *http.Server, conf Config) {
|
func setupUpload(server *http.Server, conf Config) {
|
||||||
tpl := template.Must(template.New("BaseHeader").Parse(baseHeader))
|
tpl := template.Must(template.New("BaseHeader").Parse(baseHeader))
|
||||||
template.Must(tpl.New("BaseFooter").Parse(baseFooter))
|
template.Must(tpl.New("BaseFooter").Parse(baseFooter))
|
||||||
template.Must(tpl.New("UploadForm").Parse(uploadTemplate))
|
template.Must(tpl.New("UploadForm").Parse(uploadTemplate))
|
||||||
template.Must(tpl.New("UploadError").Parse(errorTemplate))
|
template.Must(tpl.New("UploadError").Parse(errorTemplate))
|
||||||
|
template.Must(tpl.New("UploadMessage").Parse(messageTemplate))
|
||||||
|
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
// Upload form
|
// Upload form
|
||||||
|
@ -206,5 +211,8 @@ func setupUpload(server *http.Server, conf Config) {
|
||||||
tpl.ExecuteTemplate(w, "UploadError", err)
|
tpl.ExecuteTemplate(w, "UploadError", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tpl.ExecuteTemplate(w, "UploadMessage", "Upload successful!")
|
||||||
|
server.Shutdown(context.Background())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue