Skip to content

Commit ac027e4

Browse files
committed
refactor(serverHandler): rename pageData to responseData
1 parent 3bdf969 commit ac027e4

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

src/serverHandler/archiveTar.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func writeTar(tw *tar.Writer, f *os.File, fInfo os.FileInfo, archivePath string)
4545
return nil
4646
}
4747

48-
func (h *handler) tar(w http.ResponseWriter, r *http.Request, pageData *pageData) {
48+
func (h *handler) tar(w http.ResponseWriter, r *http.Request, pageData *responseData) {
4949
tw := tar.NewWriter(w)
5050
defer func() {
5151
err := tw.Close()
@@ -69,7 +69,7 @@ func (h *handler) tar(w http.ResponseWriter, r *http.Request, pageData *pageData
6969
)
7070
}
7171

72-
func (h *handler) tgz(w http.ResponseWriter, r *http.Request, pageData *pageData) {
72+
func (h *handler) tgz(w http.ResponseWriter, r *http.Request, pageData *responseData) {
7373
gzw, err := gzip.NewWriterLevel(w, gzip.BestSpeed)
7474
if h.errHandler.LogError(err) {
7575
return

src/serverHandler/archiveZip.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func writeZip(zw *zip.Writer, f *os.File, fInfo os.FileInfo, archivePath string)
4444
return nil
4545
}
4646

47-
func (h *handler) zip(w http.ResponseWriter, r *http.Request, pageData *pageData) {
47+
func (h *handler) zip(w http.ResponseWriter, r *http.Request, pageData *responseData) {
4848
zipWriter := zip.NewWriter(w)
4949
defer func() {
5050
err := zipWriter.Close()

src/serverHandler/main.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,50 +50,50 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
5050
}
5151
}
5252

53-
pageData, notFound, internalError := h.getPageData(r)
54-
if len(pageData.Errors) > 0 {
53+
data, notFound, internalError := h.getResponseData(r)
54+
if len(data.Errors) > 0 {
5555
go func() {
56-
for _, err := range pageData.Errors {
56+
for _, err := range data.Errors {
5757
h.errHandler.LogError(err)
5858
}
5959
}()
6060
}
61-
file := pageData.File
61+
file := data.File
6262
if file != nil {
6363
defer func() {
6464
err := file.Close()
6565
h.errHandler.LogError(err)
6666
}()
6767
}
6868

69-
if pageData.CanUpload && r.Method == "POST" {
70-
h.saveUploadFiles(pageData.handlerReqPath, r)
69+
if data.CanUpload && r.Method == "POST" {
70+
h.saveUploadFiles(data.handlerReqPath, r)
7171
http.Redirect(w, r, r.RequestURI, http.StatusFound)
7272
return
7373
}
7474

75-
if pageData.CanCors {
75+
if data.CanCors {
7676
h.cors(w, r)
7777
if r.Method == "OPTIONS" {
7878
return
7979
}
8080
}
8181

82-
if pageData.CanArchive && len(r.URL.RawQuery) > 0 {
82+
if data.CanArchive && len(r.URL.RawQuery) > 0 {
8383
switch r.URL.RawQuery {
8484
case "tar":
85-
h.tar(w, r, pageData)
85+
h.tar(w, r, data)
8686
return
8787
case "tgz":
88-
h.tgz(w, r, pageData)
88+
h.tgz(w, r, data)
8989
return
9090
case "zip":
91-
h.zip(w, r, pageData)
91+
h.zip(w, r, data)
9292
return
9393
}
9494
}
9595

96-
item := pageData.Item
96+
item := data.Item
9797
if file != nil && item != nil && !item.IsDir() {
9898
http.ServeContent(w, r, item.Name(), item.ModTime(), file)
9999
return
@@ -109,7 +109,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
109109
} else {
110110
w.WriteHeader(http.StatusOK)
111111
}
112-
err := h.template.Execute(w, pageData)
112+
err := h.template.Execute(w, data)
113113
h.errHandler.LogError(err)
114114
}
115115

src/serverHandler/pageData.go renamed to src/serverHandler/responseData.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type pathEntry struct {
1515
Path string
1616
}
1717

18-
type pageData struct {
18+
type responseData struct {
1919
rawReqPath string
2020
handlerReqPath string
2121

@@ -294,7 +294,7 @@ func (h *handler) getCanCors(rawReqPath, reqFsPath string) bool {
294294
return hasUrlOrDirPrefix(h.corsUrls, rawReqPath, h.corsDirs, reqFsPath)
295295
}
296296

297-
func (h *handler) getPageData(r *http.Request) (data *pageData, notFound, internalError bool) {
297+
func (h *handler) getResponseData(r *http.Request) (data *responseData, notFound, internalError bool) {
298298
requestUri := r.URL.Path
299299
tailSlash := requestUri[len(requestUri)-1] == '/'
300300

@@ -343,7 +343,7 @@ func (h *handler) getPageData(r *http.Request) (data *pageData, notFound, intern
343343
canArchive := h.getCanArchive(subItems, rawReqPath, reqFsPath)
344344
canCors := h.getCanCors(rawReqPath, reqFsPath)
345345

346-
data = &pageData{
346+
data = &responseData{
347347
rawReqPath: rawReqPath,
348348
handlerReqPath: reqPath,
349349

0 commit comments

Comments
 (0)