aboutsummaryrefslogtreecommitdiff
path: root/content
diff options
context:
space:
mode:
authorMartin Ashby <martin@ashbysoft.com>2023-08-23 07:22:14 +0100
committerMartin Ashby <martin@ashbysoft.com>2023-08-23 07:22:14 +0100
commit570d9a2503cfd06303c96f40253f80d8cee84766 (patch)
treee69ac3457cd411299677488a3d1a74a8c60867a4 /content
parenta055df62ce686038ef9b5b263dde3f5f11fe038e (diff)
downloadmfashby.net-570d9a2503cfd06303c96f40253f80d8cee84766.tar.gz
mfashby.net-570d9a2503cfd06303c96f40253f80d8cee84766.tar.bz2
mfashby.net-570d9a2503cfd06303c96f40253f80d8cee84766.tar.xz
mfashby.net-570d9a2503cfd06303c96f40253f80d8cee84766.zip
New post about comments rewrite
Diffstat (limited to 'content')
-rw-r--r--content/posts/2023-08-22-comments-2.md15
1 files changed, 15 insertions, 0 deletions
diff --git a/content/posts/2023-08-22-comments-2.md b/content/posts/2023-08-22-comments-2.md
new file mode 100644
index 0000000..9e5df20
--- /dev/null
+++ b/content/posts/2023-08-22-comments-2.md
@@ -0,0 +1,15 @@
+---
+title: "Comments 2"
+date: 2023-08-22T14:48:41+01:00
+draft: false
+---
+
+[Previously](/posts/2022-12-30-comments/) I added a basic comment system to my website using a separate web server which served only the comment HTML. This is fine, but it does require another program running continuously on my server. Since that server is a raspberry pi, and it is running a lot of other software as well, and my blog doesn't get a lot of hits (let alone comments), I thought I could do better by using the [Common Gateway Interface (CGI)](https://en.wikipedia.org/wiki/Common_Gateway_Interface). CGI doesn't require a daemon program, but instead will launch a program to generate dynamic content when someone loads the page. In this way, no memory or CPU is required until an actual page is requested. The downside is that a new process is launched for each page load, but I think that's an OK trade-off for me. I already have CGI configured on my web server for running [cgit](/posts/2022-12-31-cgit/).
+
+I also wanted to explore the [zig](ziglang.org/) programming language some more by writing an actual program with it, so I chose to rewrite it in zig.
+
+I made a [quick exploratory program](https://code.mfashby.net/cgifun/about/) just to remind myself how CGI works in Caddy, then I ported my original comments app to a [CGI app](https://code.mfashby.net/mfashby.net/tree/comments). The new app has far fewer dependencies since it doesn't embed a web server or web framework. It depends on the [zig standard library](https://ziglang.org/documentation/master/std/), [libpq](https://www.postgresql.org/docs/current/libpq.html), [mustache-zig](https://github.com/batiati/mustache-zig) and some of my own shared code from another project to do page routing.
+
+The new comments app works just the same as the old one, although with some loss of functionality - it no longer emails me when a new comment is posted. I plan to implement this, however the zig ecosystem is much less mature than rust right now, and I could not find a good email library so I might end up rolling my own.
+
+Another spin-off from this project could be a pure-zig postgres database library. Libpq is great, however it's a C library and requires linking the C standard library, and makes code less easily portable to other platforms. The [pgx](https://github.com/jackc/pgx) project shows that it's possible to have a pure-go postgresql driver, and this might be inspiration for a zig version. Another advantage of using the host language rather than the C library is making use of future [asynchronous capabilities](https://ziglearn.org/chapter-5/). \ No newline at end of file