add README + golangci config + fix lint
This commit is contained in:
+11
-11
@@ -128,8 +128,8 @@ func extractBookForm(r *http.Request) BookForm {
|
||||
}
|
||||
bf.Editor.Value = editor
|
||||
|
||||
if a := r.FormValue(bf.Authors.Name); len(a) != 0 {
|
||||
bf.Authors.Value = strings.Split(",", a)
|
||||
if a := r.FormValue(bf.Authors.Name); a != "" {
|
||||
bf.Authors.Value = strings.Split(a, ",")
|
||||
} else {
|
||||
bf.Authors.Err = ErrInvalidAuthors.Error()
|
||||
}
|
||||
@@ -141,8 +141,8 @@ func extractBookForm(r *http.Request) BookForm {
|
||||
}
|
||||
bf.Year.Value = year
|
||||
|
||||
if kw := r.FormValue(bf.Keywords.Name); len(kw) != 0 {
|
||||
bf.Keywords.Value = strings.Split(",", kw)
|
||||
if kw := r.FormValue(bf.Keywords.Name); kw != "" {
|
||||
bf.Keywords.Value = strings.Split(kw, ",")
|
||||
}
|
||||
|
||||
file, fileh, err := r.FormFile(bf.File.Name)
|
||||
@@ -179,7 +179,7 @@ func postUploadFile(w http.ResponseWriter, r *http.Request, s *services.SessionS
|
||||
http.Error(w, "unexpected error occurred", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
w.WriteHeader(401)
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
fmt.Fprint(w, buf.String())
|
||||
return
|
||||
}
|
||||
@@ -192,7 +192,7 @@ func postUploadFile(w http.ResponseWriter, r *http.Request, s *services.SessionS
|
||||
}
|
||||
|
||||
if bf.HasErrors() {
|
||||
w.WriteHeader(400)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
fmt.Fprint(w, buf.String())
|
||||
return
|
||||
}
|
||||
@@ -202,12 +202,12 @@ func postUploadFile(w http.ResponseWriter, r *http.Request, s *services.SessionS
|
||||
|
||||
dst, err := os.Create(filename)
|
||||
if err != nil {
|
||||
if err := uploadForm.Execute(buf, &BookForm{Error: "unexpected error occured while creating file"}); err != nil {
|
||||
if err := uploadForm.Execute(buf, &BookForm{Error: "unexpected error occurred while creating file"}); err != nil {
|
||||
log.Err(err).Msg("unable to generate template")
|
||||
http.Error(w, "unexpected error occurred", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
w.WriteHeader(500)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
fmt.Fprint(w, buf.String())
|
||||
return
|
||||
}
|
||||
@@ -215,13 +215,13 @@ func postUploadFile(w http.ResponseWriter, r *http.Request, s *services.SessionS
|
||||
defer dst.Close()
|
||||
|
||||
if _, err := io.Copy(dst, bf.File.Value.file); err != nil {
|
||||
if err := uploadForm.Execute(buf, &BookForm{Error: "unexpected error occured while uploading file"}); err != nil {
|
||||
if err := uploadForm.Execute(buf, &BookForm{Error: "unexpected error occurred while uploading file"}); err != nil {
|
||||
log.Err(err).Msg("unable to generate template")
|
||||
http.Error(w, "unexpected error occurred", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.WriteHeader(500)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
fmt.Fprint(w, buf.String())
|
||||
return
|
||||
}
|
||||
@@ -236,7 +236,7 @@ func postUploadFile(w http.ResponseWriter, r *http.Request, s *services.SessionS
|
||||
fmt.Fprint(w, buf.String())
|
||||
}
|
||||
|
||||
func getUploadFile(w http.ResponseWriter, r *http.Request) {
|
||||
func getUploadFile(w http.ResponseWriter, _ *http.Request) {
|
||||
uploadForm := templates.GetUploadForm()
|
||||
if uploadForm == nil {
|
||||
log.Error().Msg("unable to load upload form")
|
||||
|
||||
Reference in New Issue
Block a user