Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds get file size method #10

Merged
merged 30 commits into from
Nov 17, 2022

Conversation

vmesel
Copy link
Contributor

@vmesel vmesel commented Nov 14, 2022

Hey, I've seen that you guys are intending to use the Content Size header from the request as a way to get the file size. As I'm learning Go, here is my small contribution to #3.

Am I on the right path, @cuducos?

Copy link
Owner

@cuducos cuducos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for the contribution, @vmesel!

On top of the inline comments, I think I have three further questions:

  • having the file size might be a good reason to send ch <- DownloadStatus{} imagining the user is building a progress bar, for example; have you considered sending that info through the channel?
  • on that topic, should we check all the file sizes before starting the download, so then the user knows this info asap?
  • are you planning to write tests (and/or need help with that)?

main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
@vmesel
Copy link
Contributor Author

vmesel commented Nov 14, 2022

Hey @cuducos, thanks for the reply

  • having the file size might be a good reason to send ch <- DownloadStatus{} imagining the user is building a progress bar, for example; have you considered sending that info through the channel?

It would be a good idea, I don't know a lot about download internals, but I thought that whenever someone starts a download, we already know the size we are expecting to receive. Is it right?

  • on that topic, should we check all the file sizes before starting the download, so then the user knows this info asap?

Probably we should be able to do that and even let the user get just the file size from a link he/she/they use on the main command.

  • are you planning to write tests (and/or need help with that)?

Yes, I intend to, but I need some help mocking requests. From my POV, we should mock some requests and send multiple Content-Size headers.

vmesel and others added 3 commits November 14, 2022 14:45
Co-authored-by: Eduardo Cuducos <4732915+cuducos@users.noreply.github.com>
Co-authored-by: Eduardo Cuducos <4732915+cuducos@users.noreply.github.com>
Co-authored-by: Eduardo Cuducos <4732915+cuducos@users.noreply.github.com>
@cuducos
Copy link
Owner

cuducos commented Nov 14, 2022

I thought that whenever someone starts a download, we already know the size we are expecting to receive. Is it right?

Nope. We just know the URL.

Yes, I intend to, but I need some help mocking requests. From my POV, we should mock some requests and send multiple Content-Size headers.

In Go we don't use mocks that much, preferring dependency injection. I think that if we propagate the file size in the channel we return to the user, as ch <- DownloadStatus{…}, we can test that “side-effect” instead. Does that make sense, @danielfireman?

@danielfireman
Copy link
Collaborator

Yes, I intend to, but I need some help mocking requests. From my POV, we should mock some requests and send multiple Content-Size headers.

In Go we don't use mocks that much, preferring dependency injection.
I think that if we propagate the file size in the channel we return to the user, as ch <- DownloadStatus{…}, we can test that “side-effect” instead. Does that make sense, @danielfireman?

That sounds good to me, @cuducos. That would also make tests easier, as we could benefit from the tests we already have in place.

main.go Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Show resolved Hide resolved
@cuducos
Copy link
Owner

cuducos commented Nov 14, 2022

Also… should we retry the HEAD request? I think so…

@vmesel
Copy link
Contributor Author

vmesel commented Nov 14, 2022

Also… should we retry the HEAD request? I think so…

Should it be updated during download ir retried if status code is different than 200?

@cuducos
Copy link
Owner

cuducos commented Nov 15, 2022

Retried in case of failure (e.g. status != 200)

@vmesel
Copy link
Contributor Author

vmesel commented Nov 15, 2022

@cuducos Should this retry method stay inside the getSize function or it should be on the getSize() call?

@cuducos
Copy link
Owner

cuducos commented Nov 15, 2022

I'd say inside, just as the example I linked (high-level function downloadFile is equivalent to getSize, and retry is wrapped inside it).

Co-authored by: Eduardo Cuducos <cuducos@users.noreply.github.com>
Co-authored by: Daniel Fireman <danielfireman@users.noreply.github.com>
@vmesel vmesel requested review from cuducos and danielfireman and removed request for cuducos and danielfireman November 15, 2022 13:15
Copy link
Collaborator

@danielfireman danielfireman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty awesome stuff! Almost there!

main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
Co-authored-by: Daniel Fireman <danielfireman@gmail.com>
@cuducos
Copy link
Owner

cuducos commented Nov 15, 2022

(I just renamed the PR to better reflect what's being suggested, let me knot if I've messed it up)

@vmesel vmesel requested review from cuducos and danielfireman and removed request for cuducos and danielfireman November 15, 2022 20:46
main.go Outdated Show resolved Hide resolved
vmesel and others added 3 commits November 15, 2022 23:15
Co-authored-by: Eduardo Cuducos <4732915+cuducos@users.noreply.github.com>
Co-authored by: Eduardo Cuducos <cuducos@users.noreply.github.com>
Co-authored by: Eduardo Cuducos <cuducos@users.noreply.github.com>
@vmesel vmesel requested a review from cuducos November 16, 2022 12:41
@vmesel
Copy link
Contributor Author

vmesel commented Nov 16, 2022

Gentlemen, I think we are done with this review. What do you guys think?

Copy link
Collaborator

@danielfireman danielfireman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for going through the changes! It looks good on my side. Only small comments are below.

main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
Co-authored-by: Daniel Fireman <danielfireman@gmail.com>
Copy link
Owner

@cuducos cuducos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor suggestions, but all good. Let me know if, after adding the TODO suggested by @danielfireman, you wanna squash your commits (otherwise I do it on my end).

main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
cuducos and others added 10 commits November 16, 2022 17:18
Co-authored-by: Eduardo Cuducos <4732915+cuducos@users.noreply.github.com>
Co-authored-by: Eduardo Cuducos <4732915+cuducos@users.noreply.github.com>
Co-authored-by: Eduardo Cuducos <4732915+cuducos@users.noreply.github.com>
Co-authored-by: Eduardo Cuducos <4732915+cuducos@users.noreply.github.com>
@vmesel
Copy link
Contributor Author

vmesel commented Nov 16, 2022

Gentlemen, "It's time"! Let's merge it?

cc @cuducos @danielfireman

@cuducos
Copy link
Owner

cuducos commented Nov 16, 2022

Gentlemen, "It's time"! Let's merge it?

Unfortunately, no; the CI is 🔴 for tests and style

If you wanna take a quick look, I suggested some quick wins to tackle both issues while revising your code. I just pushed it to a temporary branch.

@cuducos cuducos merged commit 347ff2b into cuducos:main Nov 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants