This
hello world
exercise introduces you to the
Go
programming language.
Your favorite
PHB
has asked you to write program in Go, called
timeserver
,
that will serve a web page displaying the current time of day.
Your
server1
should generate a page like this:
<html>
<head>
<style>
p {font-size: xx-large}
span.time {color: red}
</style>
</head>
<body>
<p>The time is now <span class="time">6:58:48PM</span>.</p>
</body>
</html>
When the page is requested from your favorite browser, the page should display something like this:
The time is now 6:58:48 PM.
Do not worry about the quality of the html code you're generating. That's not the point of this exercise.
Since webservers are normally bound to port 80, which is a privileged port, your program should take an optional command-line argument (flag):
./bin/timeserver --port port_number
with default value of 8080. The program should terminate immediately with an error message and non-zero exit status if the chosen port is already in use.
Implement an additional flag
-V
which just writes the version number to standard output and
terminates.
The timeserver should display the time only for the
time
request, e.g.
http://localhost:8080/time
.
Otherwise, the server should return status code
404
and send this page:
<html>
<body>
<p>These are not the URLs you're looking for.</p>
</body>
</html>
There is plenty of documentation, tutorials, and video tutorials on the language at golang.org. Make liberal use of available resources, especially the language specification.
In particular, you will want to look at these library modules:
This program is not extremely complex. Unless you do something fancy (for which you will not get extra credit), your solution will consist mostly of a few function definitions, some library calls, and a bunch of print statements.
Souce code should be formatted according to the
go fmt
conventions. Include sufficient
godoc
comments to be informative without being too
verbose2
All source files should have a copyright notice comment at the top of the file.
Your submission should include a
README
3
text
file with instructions on how to build and execute your program.
You may optionally include a
makefile
or shell script containing
the incantation(s) necessary to build and run your program.
Submit a
tarball,
preferably compressed
(.tgz
),
of your
cleaned
project workspace.
Do not submit
binaries4.
Please to not throw away marks pointlessly by improperly packaging your submission.