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.
shindakun / atlg
Source repo for the "Attempting to Learn Go" posts I've been putting up over on dev.to
Attempting to Learn Go
Here you can find the code I've been writing for my Attempting to Learn Go posts that I've been writing and posting over on Dev.to.
Post Index
Enjoy this post? |
---|
How about buying me a coffee? |
Top comments (0)