refactor: added more implementation details
This commit is contained in:
parent
50e6b53091
commit
a1a9c6407f
6 changed files with 86 additions and 4 deletions
|
|
@ -4,10 +4,42 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"git.towk2.me/towk/configurator/pkg/util"
|
||||
)
|
||||
|
||||
func (s *Service) Download() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
path = strings.TrimPrefix(r.URL.Path, "/download")
|
||||
fileInfo os.FileInfo
|
||||
out *os.File
|
||||
err error
|
||||
)
|
||||
|
||||
fmt.Printf("download path: %v\n", path)
|
||||
|
||||
// determine if path is directory, file, or exists
|
||||
if fileInfo, err = os.Stat(filepath.Clean(path)); err != nil {
|
||||
if fileInfo.IsDir() {
|
||||
// recursively walk dir acompressednd get all filenames
|
||||
// download directory as archive
|
||||
out, err = os.Create(fmt.Sprintf("%s.tar", path))
|
||||
if err != nil {
|
||||
|
||||
}
|
||||
err = util.CreateArchive([]string{path}, out)
|
||||
if err != nil {
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
// download individual file
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue