0

Downloader project in Golang

I am attempting to solve the Downloader project in Golang. There 3 files that we have to use Concurrency in order to get the sum of all three files. The files are represented by variables s1, s2, and s3 and channels ch1, ch2, and ch3 have been created to pass the files through using a downloader function. The error I receive is for lines 24, 25, and 26 whicj correspond to the following: go download(s1, ch1) go download(s2, ch2) go download(s3, ch3) The error says that undefined: downloader for all 3 lines. What does this mean and how do I go about fixing or defining the downloaders? The downloader function I have goes like this: func downloader(s int, c chan int){ sum:=0 for i:=0;i<=s(the variable);i++{ sum += i } c<-sum } At the end in the main(), to sum up the three files through the 3 channels I wrote: fmt.Println(<-ch1 + <-ch2 <-ch3). Yeah, not sure if this makes sense, but if someone can give me so.e i sight into the error of my ways, I qould be teuly grateful. Thx

10th Dec 2021, 2:50 AM
Robert Haugland
Robert Haugland - avatar
4 Respostas
+ 1
for i:=0;i<=s(the variable);i++{ sum += i } What is it: s(the variable) 😳 fmt.Println(<-ch1 + <-ch2 <-ch3) - where is another + ☺️
10th Dec 2021, 3:42 AM
Solo
Solo - avatar
+ 1
I was so impressed by this entry: "i <= s(the variable)" that I no longer began to pay attention to the "downloader". So all you had to fix was: func download(s int, c chan int){ sum := 0 for i:=0; i<=s; i++ { sum += i } c <- sum } There is no need for an additional "from" argument, especially since this name is reserved and you cannot use it as a variable name, (I don’t understand at all how it passed the test 🤔). And in general, you cannot change the code proposed in the task, if this is not stated in the task itself. Anyway, I congratulate you on completing the Go course. Happy coding! ☺️
11th Dec 2021, 6:16 AM
Solo
Solo - avatar
0
Vasiliy, I solved it. I changed a couple things after rereading the assignment and correcting my mistakes. Basically I was to create a "downloader" function that used channels to pass to go routines. The function needed to add the item from three lists (s1, s2, s3). The part I missed is that the function needed to start from 0 and go to the s number. So I changed the function to look like this: func downloader(from, to int, ch chan int) var sum int sum = 0 for i:=from; i<=to; i++{ sum += i } ch<-sum } Then the main() the channnels were already made and so were the go routines but I added the parameter 0, s1 and 0, s2.... to match the arguments I created in the fucntion. Then the last thing I noticed is that I named the function "downloader" and the go routines had them listed as "download", hence the reason for the error: download undefined. So, I changed the go routine names to "downloader" to match the func name and it all worked. As for me leaving out the extra "+" in the original question, that was just a typo here but not on the assignment. Thanks for your response in attempting to help me with this.
11th Dec 2021, 2:05 AM
Robert Haugland
Robert Haugland - avatar
0
Post full code of downloader
23rd Jan 2022, 1:18 AM
𝓑ad¢od🅴r
𝓑ad¢od🅴r - avatar