Skip to content

Commit 5764f8e

Browse files
committed
update packages
1 parent b1fcbdc commit 5764f8e

File tree

4 files changed

+39
-37
lines changed

4 files changed

+39
-37
lines changed

cmd/start.go

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package cmd
22

33
import (
4+
_ "embed"
45
"fmt"
56
"io"
6-
"io/ioutil"
77
"net/http"
88
"os"
99
"path/filepath"
@@ -13,6 +13,9 @@ import (
1313
"github.com/spf13/cobra"
1414
)
1515

16+
//go:embed static/upload.html
17+
var uploadHTML string
18+
1619
var folder string
1720
var filePath string
1821
var port int
@@ -76,23 +79,7 @@ var startCmd = &cobra.Command{
7679
}
7780

7881
func uploadPage(w http.ResponseWriter, r *http.Request) {
79-
htmlContent := `<!DOCTYPE html>
80-
<html lang="en">
81-
<head>
82-
<meta charset="UTF-8" />
83-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
84-
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
85-
<title>Upload Files</title>
86-
</head>
87-
<body>
88-
<form enctype="multipart/form-data" action="/api/upload" method="post">
89-
<input type="file" multiple="multiple" name="files" />
90-
<input type="submit" value="upload" />
91-
</form>
92-
</body>
93-
</html>
94-
`
95-
w.Write([]byte(htmlContent))
82+
w.Write([]byte(uploadHTML))
9683
}
9784

9885
func uploadFile(w http.ResponseWriter, r *http.Request) {
@@ -105,7 +92,7 @@ func uploadFile(w http.ResponseWriter, r *http.Request) {
10592
file, err := fh.Open()
10693
if err != nil {
10794
fmt.Println(err)
108-
w.WriteHeader(400)
95+
w.WriteHeader(http.StatusBadRequest)
10996
w.Write([]byte("Error retrieving the file"))
11097
return
11198
}
@@ -119,10 +106,10 @@ func uploadFile(w http.ResponseWriter, r *http.Request) {
119106
fmt.Printf("MIME type: %+v\n", fh.Header["Content-Type"])
120107

121108
// 3. write temporary file on our server
122-
tempFile, err := ioutil.TempFile("", "http-upload-*")
109+
tempFile, err := os.CreateTemp("", "http-upload-*")
123110
if err != nil {
124111
fmt.Println(err)
125-
w.WriteHeader(500)
112+
w.WriteHeader(http.StatusInternalServerError)
126113
w.Write([]byte("Error creating temp file"))
127114
return
128115
}
@@ -131,7 +118,7 @@ func uploadFile(w http.ResponseWriter, r *http.Request) {
131118

132119
if _, err := io.CopyN(tempFile, file, fileSize); err != nil {
133120
fmt.Println(err)
134-
w.WriteHeader(500)
121+
w.WriteHeader(http.StatusInternalServerError)
135122
w.Write([]byte("Error saving the file"))
136123
return
137124
}
@@ -155,5 +142,5 @@ func uploadFile(w http.ResponseWriter, r *http.Request) {
155142

156143
// done
157144
fmt.Printf("Successfully Uploaded File\n\n\n")
158-
http.Redirect(w, r, "/", 302)
145+
http.Redirect(w, r, "/", http.StatusFound)
159146
}

cmd/static/upload.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
7+
<title>Upload Files</title>
8+
</head>
9+
<body>
10+
<form enctype="multipart/form-data" action="/api/upload" method="post">
11+
<input type="file" multiple="multiple" name="files" />
12+
<input type="submit" value="upload" />
13+
</form>
14+
</body>
15+
</html>

go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
module github.com/techstark/http-server
22

3-
go 1.23.1
3+
go 1.24.4
44

55
require (
6-
github.com/mdp/qrterminal/v3 v3.2.0
7-
github.com/spf13/cobra v1.8.1
6+
github.com/mdp/qrterminal/v3 v3.2.1
7+
github.com/spf13/cobra v1.9.1
88
)
99

1010
require (
1111
github.com/inconshreveable/mousetrap v1.1.0 // indirect
12-
github.com/spf13/pflag v1.0.5 // indirect
13-
golang.org/x/sys v0.14.0 // indirect
12+
github.com/spf13/pflag v1.0.6 // indirect
13+
golang.org/x/sys v0.29.0 // indirect
1414
golang.org/x/term v0.13.0 // indirect
1515
rsc.io/qr v0.2.0 // indirect
1616
)

go.sum

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
1+
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
22
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
33
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
4-
github.com/mdp/qrterminal/v3 v3.2.0 h1:qteQMXO3oyTK4IHwj2mWsKYYRBOp1Pj2WRYFYYNTCdk=
5-
github.com/mdp/qrterminal/v3 v3.2.0/go.mod h1:XGGuua4Lefrl7TLEsSONiD+UEjQXJZ4mPzF+gWYIJkk=
4+
github.com/mdp/qrterminal/v3 v3.2.1 h1:6+yQjiiOsSuXT5n9/m60E54vdgFsw0zhADHhHLrFet4=
5+
github.com/mdp/qrterminal/v3 v3.2.1/go.mod h1:jOTmXvnBsMy5xqLniO0R++Jmjs2sTm9dFSuQ5kpz/SU=
66
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
7-
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
8-
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
9-
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
10-
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
11-
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
12-
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
7+
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
8+
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
9+
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
10+
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
11+
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
12+
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
1313
golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek=
1414
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
1515
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

0 commit comments

Comments
 (0)