audio selection works
This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// Makes a GET request to the specified URL and returns the JSON response
|
||||
@@ -52,3 +54,30 @@ func GetJSON[T any](url string) ([]T, error) {
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// Download downloads a specified object at a given url and places it in
|
||||
// the provided dest directory.
|
||||
func Download(name string, path string, url string) error {
|
||||
fullFilePath := filepath.Join(path, name)
|
||||
if err := os.MkdirAll(path, os.ModeDir); err != nil {
|
||||
return err
|
||||
}
|
||||
file, err := os.Create(fullFilePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
_, err = io.Copy(file, resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user