restructuration
This commit is contained in:
@@ -12,18 +12,18 @@ import (
|
||||
|
||||
const URL = "/download"
|
||||
|
||||
func Handler(bs services.IStore) func(http.ResponseWriter, *http.Request) {
|
||||
func Handler(s services.IStore) func(http.ResponseWriter, *http.Request) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
getDownload(w, r, bs)
|
||||
getDownload(w, r, s)
|
||||
default:
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getDownload(w http.ResponseWriter, r *http.Request, bs services.IStore) {
|
||||
func getDownload(w http.ResponseWriter, r *http.Request, s services.IStore) {
|
||||
queryParams := r.URL.Query()
|
||||
downloadFiles, ok := queryParams["file"]
|
||||
if !ok {
|
||||
@@ -39,7 +39,7 @@ func getDownload(w http.ResponseWriter, r *http.Request, bs services.IStore) {
|
||||
}
|
||||
|
||||
filename := downloadFiles[0]
|
||||
filePath := filepath.Join(bs.GetStoreDir(), filename)
|
||||
filePath := filepath.Join(s.GetDir(), filename)
|
||||
|
||||
if _, err := os.Stat(filePath); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
|
||||
Reference in New Issue
Block a user