Hash Server 9000 in Go

I took an internal dev challenge at work a while back because I wanted to learn more Go since I have an OO background and was not familiar with the procedural way of thinking. The goal was to build a simple non-persistent password hashing service using only the standard library while demonstrating the use of concurrency with the endpoint requirements below.

Reading the blue and white book was definitely key to gaining deeper insight. It was super challenging and I tested as much as I could. There are probably many areas for improvement but it was fun and I learned a ton so I thought I’d share.

I made a similar golang subreddit post and I got more engagement than expected. People assumed that this was a production service when it was more for learning Go concepts. It received lots of critique but there were insightful opinions and made changes accordingly. It’s amazing how the world response when you learn in public.


Hash Server 9000


  1. POST /hash - Hash and encode a password string. The request must contain a password parameter. Returns the id of Base64 encoded string of the password that’s been hashed with SHA512 with a 5 second delay to simulate asynchronous processing. Example: curl --data "password=angryMonkey" http://localhost:8080/hash
  2. GET /hash/:id - Retrieve a generated hash with the id (after approximately 5 seconds), otherwise you will receive error id not found. Example: curl http://localhost:8080/hash/1 will return: ZEHhWB65gUlzdVwtDQArEyx+KVLzp/aTaRaPlBzYRIFj6vjFdqEb0Q5B8zVKCZ0vKbZPZklJz0Fd7su2A+gf7Q==.
  3. GET /stats - Statistics endpoint. Returns a JSON object with the total count of the number of password hash requests made to the server so far and the average time in milliseconds it has taken to process all of the requests. Example: curl http://localhost:8080/stats, will return: {"total": 1, "average": 123}
  4. GET /shutdown - Graceful shutdown. When a request is made to /shutdown the server will reject new requests and wait for any pending/in-flight work to finish before exiting.


What did you think about this post? jude@jq1.io