Several years ago I decided to run an experiment.
I had a few humble goals:
- Experiment with Gopherjs - a transpiler that converts Go code to JavaScript
- Create a few simple exercises to improve my German
- Leverage Cloudflare for free TLS to give me the s in https, and so I don’t have to muck with certificates
- Use a bootstrap to make the site look not completely terrible
- Host an interactive web page on AWS with ec2 and Route 53 with a Go backend to serve the pages and provide server-side validation for the exercises on the site
Thus, the https://theawfulgermanlanguage.com/ was born.
Gopherjs
Why would someone want to transpile Go code to javascript?
Aren’t there enough languages that compile to javascript already?
Here are a couple of reasons it may be useful:
- Reuse - leverage the same models or code defined in your backend
- You hate context switching away from Go and want to do “all the things” in it
I do find it super neat! I also think unless you have a great reason to use this over a mature and established front-end framework, you should probably avoid it. I’m not quite sure how it can compete with, say, TypeScript when it comes to generating efficient, robust code that is likely to work on a broad range of browsers.
By its nature, there is also lagging support behind the latest version of Go. As of this writing, GopherJS supports Go 1.19, but the latest version of Go is 1.22. I think this unfortunate lagging also defeats some of the benefit of having “all the things” in Go, because now you’re having to use two different versions of Go.
To summarize, unless you have the perfect reason to use Gopherjs, this may be a toy more than something you’d want to use in a production system.
Interactive German Exercises
This is no Duolingo - in fact it’s a super bare bones and ugly gopherjs frontend and server validated backend that was again was really just a toy. I do love Mark Twain’s essay on the repeated occurrence of Schlag and Zug in German and all the different meanings they can have based on context, the absurdly long words you can form, and the complexity of declension.
I made three small exercises:
Again, it’s the most rudimentary UI imaginable, but hey this was just an experiment in gopherjs!
Summary - German grammar rules are crazy.
Putting the S in HTTPS - Cloudflare
When I first created the site many years ago, it was simply http and I don’t recall there being any significant warnings about it on chrome. Well, at some point that changed and chrome rightfully berated you for having the audacity to visit a site that was not https.
My first approach was to explicitly serve https from my go server and obtain a certificate from let’s encrypt. I got it working for a couple of months, and I thought I setup up the auto-renewing correctly. I did not. Eventually my cert expired and my site was inaccessible. This led me to Cloudflare, which boasts free tls certs. I signed up for a free Cloudflare account, updated my domain registrar’s settings to point to Cloudflare’s name servers and I haven’t had to worry about mucking with certs since. Oh, I also get DDoS protection for free, which is nice.
Summary - Cloudflare’s free tier is 100% worth it for not having to muck around with certs.
Bootstrap
I admit that front-end development is not my forte yet. I wanted something simple and easy to use, and I recall finding a bootstrap theme site, e.g. https://themes.getbootstrap.com/
Summary - anything that keeps me away from manually spending hours on CSS is a win. If it looks good on mobile, that’s another big win. Bootstrap can help me on both fronts there.
AWS - Route 53 & EC2
Since this site uses back-end validation for the exercises, I couldn’t get away with a simple and free approach such as github pages. Another option would have been to use a Raspberry PI and done some dynamic dns via no-ip but part of this exercise was almost as a kata - I want to maintain some baseline competency is running cloud services myself.
Summary - Very easy to use for a simple case like this, though costs ~$5-6 a month. If I was being more cost conscious I would opt for no-ip to use dynamic dns (since ISPs love to change your IP address) and host from home.
Conclusion
- Gopherjs is a fascinating transpiler - though I wouldn’t want to use it for production code.
- German grammar is crazy
- Cloudflare is amazing for free cert management and DDoS protection
Resources
- https://github.com/gopherjs/gopherjs
- https://theawfulgermanlanguage.com/TheAwfulGermanLanguage.html
- https://pkg.go.dev/net/http#ListenAndServeTLS
- https://www.cloudflare.com/application-services/products/ssl/
- https://www.reddit.com/r/golang/comments/51q8dm/i_wonder_what_are_the_advantages_of_js_code/
- https://en.wikipedia.org/wiki/German_declension
- https://www.noip.com/