loading...
Cover image for Attempting to Learn Go - Building a Downloader Part 01

Attempting to Learn Go - Building a Downloader Part 01

shindakun profile image Steve Layton Originally published at shindakun.glitch.me on ・2 min read

Attempting to Learn Go (23 Part Series)

1) Attempting to Learn Go - Building a Downloader Part 01 2) Attempting to Learn Go - Building a Downloader Part 02 3 ... 21 3) Attempting to Learn Go - Building a Downloader Part 03 4) Attempting to Learn Go - Building a Downloader Part 04 5) Attempting to Learn Go - Building a Downloader Part 05 6) Attempting to Learn Go - Consuming a REST API 7) Attempting to Learn Go - Continuing REST Adventures 8) Attempting to Learn Go - Now Sending REST Requests 9) Attempting to Learn Go - REST API and A Bit On Templates 10) Attempting to Learn Go - Sending Email Via API Again 11) Attempting to Learn Go - Let's Get Modular! 12) Attempting to Learn Go - Let's Get Modular - Again! 13) Attempting to Learn Go - Building Dev Log Part 01 14) Attempting to Learn Go - Building Dev Log Part 02 15) Attempting to Learn Go - Building Dev Log Part 03 16) Attempting to Learn Go - Building Dev Log Part 04 17) Attempting to Learn Go - Building Dev Log Part 05 18) Attempting to Learn Go - Listing Files By Extension 19) Attempting to Learn Go - Sorting and Moving Files by Extension 20) Attempting to Learn Go - Issuer 01 21) Attempting to Learn Go - Issuer 02 22) Attempting to Learn Go - Issuer 03 - Cloud Function Go! 23) Attempting to Learn Go - Issuer 04 - Addendum

Over the past couple of months, I've been playing with Go and have enjoyed it. Now that I have a bit of free time on my hands its time to double down strengthen my skills. I also wanted to get into the habit of writing more and this is the perfect opportunity. So, let's get going and hack together a small server over the next few posts.

Idea

One of the biggest problems I've had is trying to come up with something to work on. I wanted to start this series a few days ago but, couldn't decide on what to build. It needs to be small enough that I can finish the skeleton within a few hours. Yet it needs to be complex enough to help expose me to more of the language. I thought about it and decided to design a simple server that downloads files from a remote server. The idea has some practical origins, from time to time I see something I may need. Something that I don't need at the moment, but, something I can archive and come back to later if needed. If I'm on a web page, then I want to right-click and choose a menu option and not have to think about it again right then. Like a Dropbox, I can throw a file URL at and have it take care of everything else.

Sure it may seem like overkill (and it probably is) but, I need a project to work on...

High Level

Our downloader is going to be a simple web application. Near the end of the project, I'm going to look into using Let's Encrypt to serve HTTPS from the app. Since this is a kind of archive the server will live off-site. For testing, a micro-instance of the Google Compute engine will work. I am going to attempt to use only the Go standard library for as long as possible. This is a learning exercise after all.

To start with the server itself will have two end-points:

http://<server>/

  • GET / - simple server status, uptime probably.

http://<server>/download

  • PUT POST /download - accept a JSON object with download details

JSON Object

{
  "title": "Name of download (filename probably)",
  "location": "URL of download"
}

The server will receive the JSON, parse it, and then issue a GET request to download the file. Once retrieved we save the file to disk. For now, let's gloss over how the JSON object gets created in the first place. We'll come back to that at some point. With a basic idea in place, I'm going to write some code and try to document what I'm doing as I work along each little sprint.

Until tomorrow...

Part Two has been posted.


You can find the code for this and most of the other Attempting to Learn Go posts in the repo on GitHub.



Attempting to Learn Go (23 Part Series)

1) Attempting to Learn Go - Building a Downloader Part 01 2) Attempting to Learn Go - Building a Downloader Part 02 3 ... 21 3) Attempting to Learn Go - Building a Downloader Part 03 4) Attempting to Learn Go - Building a Downloader Part 04 5) Attempting to Learn Go - Building a Downloader Part 05 6) Attempting to Learn Go - Consuming a REST API 7) Attempting to Learn Go - Continuing REST Adventures 8) Attempting to Learn Go - Now Sending REST Requests 9) Attempting to Learn Go - REST API and A Bit On Templates 10) Attempting to Learn Go - Sending Email Via API Again 11) Attempting to Learn Go - Let's Get Modular! 12) Attempting to Learn Go - Let's Get Modular - Again! 13) Attempting to Learn Go - Building Dev Log Part 01 14) Attempting to Learn Go - Building Dev Log Part 02 15) Attempting to Learn Go - Building Dev Log Part 03 16) Attempting to Learn Go - Building Dev Log Part 04 17) Attempting to Learn Go - Building Dev Log Part 05 18) Attempting to Learn Go - Listing Files By Extension 19) Attempting to Learn Go - Sorting and Moving Files by Extension 20) Attempting to Learn Go - Issuer 01 21) Attempting to Learn Go - Issuer 02 22) Attempting to Learn Go - Issuer 03 - Cloud Function Go! 23) Attempting to Learn Go - Issuer 04 - Addendum

Posted on by:

shindakun profile

Steve Layton

@shindakun

I've been known to write some code from time to time.

Discussion

markdown guide