Skip to content

Commit 2acfcd2

Browse files
Luis G. Villegaszupzup
Luis G. Villegas
authored andcommitted
Added template for testing directly in the browser
1 parent bdac7db commit 2acfcd2

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

Diff for: main.go

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"net/http"
1010
"os"
1111
"path/filepath"
12+
"html/template"
1213
)
1314

1415
const maxUploadSize = 2 * 1024 * 1024 // 2 mb
@@ -26,6 +27,11 @@ func main() {
2627

2728
func uploadFileHandler() http.HandlerFunc {
2829
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
30+
if r.Method == "GET" {
31+
t, _ := template.ParseFiles("upload.gtpl")
32+
t.Execute(w, nil)
33+
return
34+
}
2935
if err := r.ParseMultipartForm(maxUploadSize); err != nil {
3036
fmt.Printf("Could not parse multipart form: %v\n", err)
3137
renderError(w, "CANT_PARSE_FORM", http.StatusInternalServerError)

Diff for: upload.gtpl

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<html>
2+
<head>
3+
<title>Upload file</title>
4+
</head>
5+
<body>
6+
<form enctype="multipart/form-data" action="http://localhost:8080/upload" method="post">
7+
<input type="file" name="uploadFile" />
8+
<input type="submit" value="upload" />
9+
</form>
10+
</body>
11+
</html>

0 commit comments

Comments
 (0)