r/CritiqueMyCode • u/karlyan • Oct 20 '18
[golang] Web server learning project and sample page
Hi!
My first time posting here. To prepare for a new job and to generally understand better how things work I started to write a web server in golang. The features so far include:
Serve HTTP GET requests
handling of log files through my own logging package, which can in theory write different events to different logs (not used in my code yet)
concurrent handling of connections via go routines
HTTPS capability using the golang crypto/tls package
parsing of config files
rudimentary CGI implementation The project is VERY rough around the edges, basically a barely running prototype. Also I'm in the process of cleaning up the code. For lot of functions I could have used (arguably better) premade functions/packages, but I decided to write those things myself for the learning experience (except for the tls implementations for obvious reasons).
Any input/comments/suggestions welcome
github repo: https://github.com/karlyan17/nurgling
example site: https://karlyan.ddns.net:8888/index.html
2
u/FuzzyStatic Jan 06 '19
I have a few comments on style:
You use snake_case for all your variables. Go typically uses camelCase or PascalCase. You can read more about it here: https://stackoverflow.com/questions/38616687/which-way-to-name-a-function-in-go-camelcase-or-semi-camelcase
You have a lot of vars defined, you can make it easier on yourself by grouping them with (). Example here: https://stackoverflow.com/questions/6937716/grouping-of-constants-in-go-language (you can group const, vars, types, etc).
Also, I would look at waitgroups to keep your goroutines "alive": https://nathanleclaire.com/blog/2014/02/15/how-to-wait-for-all-goroutines-to-finish-executing-before-continuing/