package service 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 } } } } func (s *Service) Upload() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { } } func (s *Service) List() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { } } func (s *Service) GetStatus(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") data := map[string]any{ "code": 200, "message": "Configurator is healthy", } err := json.NewEncoder(w).Encode(data) if err != nil { fmt.Printf("failed to encode JSON: %v\n", err) return } }