Skip to content

Commit a0c7c15

Browse files
committed
change dir on cover function
1 parent ddfcecc commit a0c7c15

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/app/downloader.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@ import (
1414
"github.com/coderj001/go-wallheven/src"
1515
)
1616

17-
func Downloader(searchList *src.SearchList) {
17+
func Downloader(searchList *src.SearchList, dir string) {
1818
var wg sync.WaitGroup
1919
wg.Add(len(searchList.Data))
2020
completed := make(chan bool)
2121

22+
if dir == "" {
23+
dir = src.BASE_CONFIG.DIR
24+
}
25+
2226
for i := 0; i < len(searchList.Data); i++ {
23-
go downloadImage(&searchList.Data[i], &wg, completed)
27+
go downloadImage(&searchList.Data[i], dir, &wg, completed)
2428
}
2529

2630
// Code for spinner - it takes
@@ -55,9 +59,8 @@ func Downloader(searchList *src.SearchList) {
5559
close(completed)
5660
}
5761

58-
func downloadImage(imgInfo *src.ImageInfo, wg *sync.WaitGroup, completed chan bool) {
62+
func downloadImage(imgInfo *src.ImageInfo, dir string, wg *sync.WaitGroup, completed chan bool) {
5963
defer wg.Done()
60-
dir := src.BASE_CONFIG.DIR
6164

6265
resp, err := http.Get(imgInfo.Path)
6366
if err != nil {

src/cmd/root.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ var (
1919
dir string
2020
)
2121

22-
var cfgFile string
23-
2422
var rootCmd = &cobra.Command{
2523
Use: "go-wallhaven",
2624
Version: "0.0.1",
@@ -29,7 +27,7 @@ var rootCmd = &cobra.Command{
2927
Run: func(cmd *cobra.Command, args []string) {
3028
url := app.GetFullURL(page, categories, purity, sorting, colors, query)
3129
searchList, _ := app.FetchAPI(url)
32-
app.Downloader(&searchList)
30+
app.Downloader(&searchList, dir)
3331
},
3432
}
3533

0 commit comments

Comments
 (0)