Featured
- Get link
- X
- Other Apps
Week 2: Working on LinkStatus.go
Release 0.1 Project
Hello again, this week I started and finished my release 0.1 project for my class. The project was to create a URL checker command line application with the choice of any language I wanted to use. So I decided to use GO since it is similar to C and C++ which I've worked with before so learning the basics of this language wouldn't be as rough.
Development Process
To start I ran a simple "Hello World!" like starting to learn any other language. From there I researched and learned about the net/http package which allowed me to enter a URL and receive the status code back. A few if's and else statements later and I could now test for status codes ranging from 200, 400, and unknown or bad URLs.
After I was able to receive status codes I moved on to opening and reading text from a file. I placed a URL inside and extracted that into a string to then GET request a status code.
The first real problem I encountered was finding URL's within a file filled with different text such as a .html file for example. To solve this I used the regex package to find URLs. I started by appending to a string each URL I found on a new line so I could access them easily. From there I set up a loop to read each line, make a new string, and then call my GET request function, passing along the new smaller single URL string along the way. The request would happen and then the next line of the string would be read and then sent over to the GET request function over, and over until I ran out of URL's to check.
The GET request function worked by receiving a URL in string form, ran a GET request on it, and stored the status code away. This status code was then checked for errors and ran through a few if's and else's to select the correct output to display.
Once this was done I moved onto making the command line interface. I ended up using a modified version of the flag package called pflag. Using pflag allowed me to create a custom version command so users could use "-v" or "--version" to get the version information. After this the rest of the command line setup was finish and now users could input files.
Another issue that I ran into was the program pausing for a long time on certain URL checks. To fix this I used the net/http package I was already using to introduce a timeout limit of seven seconds.
As of now the project is nearly complete with just some bug fixes and cleaning up of the code left. All major and optional features have now been implemented.
Program Features
- Colour output for status codes
- Timeout of max 7 seconds to the program doesn't stall
- Two different ways to check the version (-v or --version)
- Basic information on how to use
- Ability to read supplied files
How to use the program
Once you have the files on your system and have GO installed you can simply just run "go run LinkStatus.go" to get helpful information about the program.
To get the version of the program you use "go run LinkStatus.go -v or --version"Its funny as I literally write this blog I just noticed the URL output it counting by 2's. Another bug to fix.
Thanks for reading my second blog post! Another one is on the way for lab 1.
-Matt
- Get link
- X
- Other Apps
Comments
Post a Comment