First Go Project: A Jam-stack Commenting API
I recently have been looking around for a simple commenting system to integrate into my website. Since my website is a pre-rendered static Html site hosted on Github Pages, there is no way for it to directly store comments because it does not have a database. The only option for dynamic content to be stored is with an external service.
I kept my eyes open for a service that I liked, but I did not want to just integrate any old service into my website, I did have some requirements:
- The service should not cost anything. I would rather host something myself than sign up for another subscription (because I'm already paying for a VPS anyway).
- I want to control how the comments on my website are displayed. I quite like my website design and I don't want a generic comment box below my posts.
- The service should respect the privacy of the people using my website.
- There should be an option to comment without setting up an account with the service.
While looking around for how other people integrated comments into their static websites, I found a nice blog post from Average Linux User which compares a few popular commenting systems. Unfortunately, most systems either are not very privacy-friendly, cost money or store the comments as comments on Github issues..? After looking through the options I decided to use this opportunity to write my own commenting system and dabble with the Go programming language.
Writing a commenting API in Go
First thing first, if you want to take a look at the code, check out the Github repo.
I decided to write the commenting system in Go because I have been looking for an excuse to practice Go for a while, and this seemed like the perfect fit. It is a small CRUD app, consisting of a storage component, an API component and a small event component in the middle to easily compose the functionality I want.
Currently, it supports the following functionality:
- Listing all comments (optionally since a specified timestamp)
- Listing all comments for a specified page (optionally since a specified timestamp)
- Posting comments through the API
- A simple admin dashboard that lists all comments and allows the admin to delete them
- Email notifications when someone comments
- Email notifications when someone replies to your comment
- SQLite storage for comments
The code is built in a way to make it easy to customise the features. For example to disable features like the email reply notifications you can just comment out the line in the main.go file that registers that hook.
To write custom hooks that get executed when a new comment gets submitted or one gets deleted, just implement the Handler interface and register it in the main method.
You can also easily add other storage options like databases or file storage by implementing the Store and SubscribtionStore interfaces.
Can it be used in production? ππ¨
I currently use it on this website! Go test it out (I might delete the comments if they are rude though π€).
In all seriousness, I would not use it for a website where the comments are critical. But for a personal blog or similar, I don't see why not.
If you want to host your own version, there is a Dockerfile available. If you decide to integrate this into your website, please comment below, ping me @TiimB or shoot me an email hey@tiim.ch, I would love to check it out.
I built my first project using the Go programming language: A commenting API for the jam-stack. It is simple but easily extensible. And it powers the commenting feature of this website!
/blog/2022-07-12-first-go-project-commenting-api
Tim Bachmann
2023-08-02 9:10:04 AMI blogged about creating a comment system for my website a while ago, and later how I implemented webmentions into that same project. Since then this little go program has grown quite a bit, and it has turned into a modular platform that supports quite a few technologies:...
Anonymous
2023-07-09 7:25:02 PMHeya just saw your post on Reddit about this comment feature, didn't want to leave without using it ^^. Nicely done!
Tiim
2022-12-07 11:01:37 PMYou are right, there is not any documentation in the readme yet. Although hopefully, I will work on that soon. I'm in the middle of refactoring the project. To query the comments there are two rest endpoints ["/comment"](https://github.com/Tiim/IndieGo/blob/044b58e96dae112ceaca509f8541c84db3ef50f3/api/comment.go#L41-L71) and ["/comment/:page"](https://github.com/Tiim/IndieGo/blob/044b58e96dae112ceaca509f8541c84db3ef50f3/api/comment.go#L73-L107) which return all comments or the comments for a specific page. The comments are loaded from this API endpoint when the site is generated. To display the comments without rebuilding the site, new comments are fetched in the browser with the "?since=<time-of-last-build>" query parameter.
Poorchop
2022-12-07 10:33:44 PMGood stuff. Always nice to see a site supporting comments and/or Webmentions. Maybe I missed it in the readme but I am curious as to how one queries the API for comments. Do you pull in the comments from the database when you generate the site?
Golang Bot
2022-11-27 10:31:58 PMI published a new blog post: First Go Project: A jam-stack Commenting API tiim.ch/blog/2022-07-1β¦ #golang #jamstack #API
Tim Bachmann
2022-11-21 10:19:23 PMThis site now supports sending and receiving webmentions and surfacing structured data using microformats2.
hola
2022-07-18 8:44:11 AMhola
polite
2022-07-13 9:06:11 PMAnd a polite reply
somGuy
2022-07-13 6:31:31 PMPretty cool dudez
rude
2022-07-12 9:40:39 PMThis is a rude comment ;)
wdup
2022-07-12 1:30:14 PMGood job dude!