go podcast()

This episode was supposed to be focussing on templ, the tempalte library, but as I was going in details I found it hard not to explain the back story of why I started looking for something to help html/template be more "fun" to build rapid side projects, you know, CRUD heavy web application.

Links:
  • templ: https://templ.guide/
  • The lib I forgot the name during the episode: https://github.com/Masterminds/sprig

If you'd like to support this show the best way is to puchase my courses, I've one call Build SaaS apps in Go and another one called Build a Google Analytics in Go. Here's a direct discount for listener of this show.

Creators & Guests

Host
Dominic St-Pierre
Go system builder - entrepreneur. I've been writing software systems since 2001. I love SaaS, building since 2008.

What is go podcast()?

15 minutes news, tips, and tricks on the Go programming language.

Dominic:

Hello there. I'm Dominic St-Pierre and you're listening to Go Podcast(). Today, I have a confession to make. I written some application in something else than Go. Hello, gophers.

Dominic:

I'm a little bit more energetic these days because, well, in Quebec, Canada, the temperature is slowly returning to something acceptable. So the winter is kind of going to an end slowly but surely. So I mean, the sun is back. The light is back. So yes, a little bit more energy I would say.

Dominic:

I brought back the music, the intro music. I don't know. Yeah. I think, I think I'm still I'm still playing around with, with the format of the podcast and, you know, what what I want to do and what I don't want to do and things like that. So, I mean, yeah, the intro music is back.

Dominic:

Also, I mean, yeah, this is well, this will be a solo episode today. I will be I will be having a guest next week. But, yes, I mean, if you, again, if you if if you are interested and and would like to to propose an episode and things like that, you know, do not hesitate to, to contact me. It would be, it would be my pleasure to talk with you and see, and see what we can do. Did you, did you upgraded to Go 122 yet?

Dominic:

So there's a couple of discussion around saying that there's a couple of issues here and there sometimes with, you know, races, data data races and things like that. Or, or maybe not data races, but more like, runtime, runtime issues. A little bit here and there and a couple of other small issues with the 122. So, I mean, the the question is is now we we should ask our ourselves, you know, or even with the backward compatibility guarantee, might be an idea to depending on on what, you know, the type of, operation that you are doing at your company, you know, should you should you wait? Should you wait a little bit?

Dominic:

Maybe for the my the first minor version, which is which is a little bit sad to say because, you know, Go is is is having such a a stellar, track record and things like that. I mean, the the compiler and things like that, the the language overall. So, I mean, I, I I I was, I worked for a long time in in a fintech, you know, company in the financial industry. And I mean, to me, it it was you know, stability was was was paramount. I mean, it was it was required to have the system be up and running as much as possible.

Dominic:

So I I would say that, I I'm I'm I'm not the one that was, pushing to upgrade the version when when a new major version was, was, released. The thing is when, yes, when you are publishing a library, for example, then you you kind of it it's a it's a more it's a more difficult decision to make because now there will be there will be some some of your users and, quote, unquote, users, you know, packages and and programs that depends on your library that that will want to, to upgrade and things like that. I mean, so, yes, it's a touchy, it's a touchy thing. I'm sure I'm sure you all thought about that and things like that. But, you know, might be, I I hope that we will not enter this, you know, this era of, being a little bit afraid of upgrading because that that was not my experience so far with Go.

Dominic:

So, I mean, yeah. That's, that's something to to think about a little bit. Alright. Let's move on to our main topic of the day, and it will be about, well, you know, templates in in Go. I mean, when you are building a web application, and not just an API, for example, at some point, you will probably want some template.

Dominic:

And more specifically, the the the the temple package, you know, templ. Not sure if it's if it's pronounced temple or what. But, let's just say that it is. And, I will be completely frank here and honest. When I saw the package at first and what it was doing, I was like I don't know.

Dominic:

My reaction was a little bit more towards the, you know, something like, well, I'm I'm not sure I'm not sure if addressing the problem, if if there is any problem. To me, go the HTML slash template package is just good. You know, it and, you know, I I did not really saw the value at first of Temple. I'm not I'm not even sure that that I'm seeing it. So again, I haven't used it yet in production.

Dominic:

I just want to talk a little bit about the the template, situation in Go. Because there's a backstory to all of this. To be, you know, to continue in my honesty, I will I will have to admit that in the past, I don't know, maybe 3 or 4 months, I I will admit that I have dabbled or at least look at some other languages and and and framework to build, to build some some small, some small web applications. So Django and Python was, was the one. Why why I'm saying that is is that I I kind of discover a little bit what a couple of problem that I think was hard or at least, you know, building web application in Go is deep you know, depending on what type of application.

Dominic:

But let's say let's say, yeah. Let's let's go a little bit one step further in my backstory. So I needed to to cut some, some subscription of mine. So I was adding 2, 2 web application that I was using. So the first one was FreshBooks, basically, to hold my consulting company, invoices and kind of accounting ish.

Dominic:

So, they raised their price and, you know, it was it was it was a long discussion of of of mine with, my wife and I. So, basically, she's doing, she's doing some, some accounting in in the company and whatnot. But, you know, long story short, I said to myself, you know, screw that. I will just build myself a small a small web application that, you know, that that just have some, invoicing functionalities and some kind of I need I need some recurring. I have some some client that, I I do hosting to and I charge them, you know, for, a monthly, a monthly fee and what and whatnot.

Dominic:

So, you know, something very, very, small and simple invoicing, time tracking, recurring, recurring invoicing, and, you know, with Stripe billing and whatnot. It took, took me like 2 days to build, in Django and Python. And, I did not really add prior experience with Django, to be frank. It it was something that I wanted to, to to use. The other application, well, it it was to host my my own online courses, basically.

Dominic:

So I was using another another services, and they they kind of, made a feature pay you know, a paid feature. So something that was included in my subscription. And at some point, they decided, well, you know what? We will we will charge for that. And I I said, alright.

Dominic:

You know, I'm a programmer. I have some times ahead of me, so I decided to do that. Of course, you know, this this might sound crazy. And to be frank, I I had sometimes because I I keep saying that, but, you know, I I I kind of was part of an acquisition last year. And, in November of 2023, my my kind of mandate or my contract with with the the acquirer stopped.

Dominic:

So I decided to take a little bit of time to myself. I wanted to build a course. So I built a course that was that that that is named build a Google Analytics in Go. And, and yes. I mean, that that was the backstory.

Dominic:

So why didn't didn't, I chose Go, first of all? I needed to be extremely quick. Those types of application are mostly CRUD ish application. To be completely honest, I have said it many times. I I don't think I don't think that Go is the best choice for these types of application.

Dominic:

After after a couple of months, I'm I'm I'm not sure I'm not sure I'm I'm still I'm still game of saying that. Because as much as I I I final I found the experience, you know, quick and interesting, I'm not sure I would like to have a a production system, built in in Python Django, to be to be completely honest. And and I'm I'm not I'm I, you know, I I don't want to bash. I still I still really like, the framework. I think they they they did a very great, great job with it.

Dominic:

And I'm probably not doing enough, you know, enough test to be confident, and things like that. So I mean, the the fault is on me. I'm I'm not I'm not bashing the the language nor the framework at all here. It's just that I found myself missing Go during during this time. But it also made me, wonder, you know, what what is what is exactly wrong?

Dominic:

What is my problem with building kind of CRUD application with Go? Because I I've did an an episode on, you know, handling database queries in Go. So the the the entire story about the SQL database is is, is very, very well done. Don't get me wrong here. But the amount of code that one needs to write, is is kind of extremely verbose.

Dominic:

It's very repetitive, not fun at all. There's a couple of library and I, you know, I don't want to rehearse the entire episode. So if you want, if you want to to know my my probably biased opinion on the subject, you you may, you may listen to the show. But, you know, suffice to say that I I had the chance by by looking at something else I had the chance to really ask myself some question. You know what?

Dominic:

What's you know. And and this is me talking to me. You know, what's what is your problem with Go exactly? What and the template is also something that I did not really I I I could not really add put that in Word back, back in the days. But now that I've that I've built a couple of application with Django, I think, I think that the template is is very good, but it's not enough to it's, you know, it's it's not enough.

Dominic:

There's not enough enough functionalities, for for the template. Just just things like, you know, the entire the entire, filter in in Django. And I I don't want to be, to to talk too much about Django in here. It's it's not the point. I don't want a framework in Go as well.

Dominic:

I just want some quick functionalities. And the, you know, the func map of the the template is is a good place to to do that. And I've I've used that multiple times. In fact, probably in in all my project, I I'm always creating some, some functionalities. So, you know, think think things like, you know, internationalization, for example, is is kind of a little bit harder to do.

Dominic:

Every everything that that touches the, you know, the front end in in a sense in Go is kind of is kinda harder. You you you still have to to build a lot of things yourself. Let's let's just say that. So when I when I first saw the the temple, you know, what temple is trying to do or or at least what I understand that Temple is trying to do, my my point of view, I did not really really liked it. You know, you have you have now a completely separate, you know, file, file extension or at least a a file format to build your, you know, your web application views or whatever.

Dominic:

You know, call that what you want. Pages, views, component. I I don't, I don't know exactly how those things are called, but, template. What I I I told myself, why? You know, why?

Dominic:

We don't really need a new a new format. HTML is good. You know, non developers can edit those files very easily. They understand the the syntax and things like that. And now you have you have kind of a at first glance, it looked to me something like, you know, what JSX is for React, for example.

Dominic:

So if you don't if you are not, you know, used to React and things like that, let's just just say that it's kind of mixing JavaScript with HTML. So it's kind of it's kind of re remind me of the of the old, I I came from the the classic ASP back in the days where, you know, PHP was like that, when when I when I started my first, my first web web application was like in 97 or something like that, and it was in PHP. And, but I I, my first job was with ASP, classic ASP. And and those two things, you you kind of mixed a lot of code in your, in your, HTML. So we we've moved from from that, a long time ago.

Dominic:

So JSX is is obviously way cleaner. I mean, I'm I'm not saying that you are mixing too much, code, inside inside your but you're you're still you're still having some, you know, a different, a different experience other than writing plain HTML. And that was my first, my my first thought when I saw Temple was now, you know, now you need to to have this, this new file extension. You need to compile those templates. And finally, you have you have some, some some code that is so so so you you you have another another compilation process.

Dominic:

I I don't there was a lot of things that I did not really like about, to be frank. And a couple of weeks ago, I was was start starting to to think a little bit like, how can I how can I make the template and go a little bit more fun to work with? You know, to me it it it always return to to having fun and things like that. You know, not, so Django was fun. To be frank, creating creating the template in Django, creating the the HTML view, the application UI.

Dominic:

I hate it, but I still do. And, you know, it's something I I'm I've been doing for 4 years. I mean, how can we bring that to go? I mean, is it possible? Is it even possible?

Dominic:

So temp you know, temple was was not the answer. But I I I said to myself, you know what? Let's just let's just have a look at at their documentaries. I read I read the entire documentation. And they almost, you know, they almost convinced me to try it.

Dominic:

I haven't yet. I'm I'm still I'm still unsure I want I would like to go that route. I I I think I would still prefer to try and bring maybe some some layer on top of HTML template to bring a lot of functionalities that that would help, you know, just just, having having a little bit more easier time to build, the UI of of the application. But that, you know, that that is something, that I'm still I'm still thinking. Maybe there there's some libraries as well.

Dominic:

I've I found, I found one which now the name, is evading me, but it will it will be on the show notes. But, but yes, there's a there's some libraries that, that already, you know, kind of feel the func map like I'm saying and and giving giving lots of, you know more built in functionalities on the templates. So returning to the story, I mean, so that's that's a little bit why I I, I did not choose, Go for for those 2 application. I kind of I kind of regret it a little bit, now, after the fact. It was it was extremely quick.

Dominic:

To be to be frank, I I I'm not sure I've said it, but took me 2 days to write or maybe 3. Let's say let's say 3. Whatever. To write the, you know, the invoicing application with recurring, you know, recurring invoices, Stripe Charge, and things like that. I mean, it's we cannot deny the fact that, you know, Django is very, very quick to build that kind of application.

Dominic:

But still still today after after, it's it's what? Like, 5 let's say 4 months, 5 5 months. I'm starting to missed to miss Go a little bit. So, so that's why, you know, that that's something I I I'm I might want to, to start investigate a little bit. You know?

Dominic:

Is it is it going to be something a library that that I will build? You know, will I, will I contribute to the one that I found, which which look look nice. I mean, but they they seems to be abandoned for, for a long time. So I'm not sure. I'm not sure.

Dominic:

I might I might want to reach out to, to the maintainer and and things like that to see, you know, see what's going on with that and, you know, why why, why they they are they are stopping the development of that. Maybe maybe maybe the library is is completed. I I I don't know. The the point is, I mean, when you are building an app an API in Go, which which is probably the the best use case for Go in my opinion. But sometimes, I would like for me, for the, for, for, you know, for the, the me of the future to find a way to be as productive and have as much fun with building CRUD like application, you know, very very simple application in Go instead of having to revert to to Python and Django for example or Rails for example and things like that.

Dominic:

And, you know, some some of you might say, well, you you should you should try buffalo and things like that. Well, no. No. No. No.

Dominic:

No. This isn't this is not what I'm what I'm talking at all because now I yes. I I I don't I'm, yes. I I don't really want to use a framework that exists because in my opinion, I I don't I don't want to have any, any kind of back end, you know, functionalities written for me and things like that. I I this this is also fun for me.

Dominic:

This is this is something that I like to do. The problem is mostly on the UI and on the database. But yet, I I I would not also want to use Gorm. So Gorm, the the ORM is not is not the solution for me. So I've I've talked about that in in in that previous episode that I'm that I'm referring to the, a couple of minutes ago.

Dominic:

So that's not the solution as well. So the solution I I don't know what it is. Maybe it's temple, maybe not. I will I will have to test it. I know I know that it it is really, you know, it's it's gaining in popularity and and things like that.

Dominic:

I I I don't know that I like the fact to have to compile something. So if you haven't seen it, it it's nice. I mean, you're you're you're kind of building your application in in in kind of small component way, with with this mindset. A little bit a little bit like I don't know. It's those, those, JavaScript, front, you know, framework and whatnot.

Dominic:

So you're you're calling your component with, with with an at symbol. You can you can do at and the function name or at and the the package name and the function name. There's a there's a lot of of, of code that that that is, you know, that replicates Go format, for example, the, you know, you can do some if, you can do some, some for loops. So the idea is good, but I'm I again, this is this is kind of mixing HTML with with Go a little bit. And now, you need to compile those things before using it.

Dominic:

The the this compiles to, the to, to a a template basically. So you can render that directly and things like that to a an IO reader. I mean, it's it's it's very nice. It's beautifully designed. It seems to be, it seems to be well taught and things like that.

Dominic:

I'm just unsure that for me it's going to, it's going to fix my problem with with prototyping a web application in GoA, especially especially a a non API. So a more a more traditional monolith application. Let's say that yes. Let's say that that you want to build an invoicing application in in your weekend. You know?

Dominic:

Can you do that and go, you can. You can. But it it it might takes a a couple of days in addition to that. Because of the database and because of the template. Not because of the back end stuff.

Dominic:

The back end stuff will be in my opinion way more solid than Go for sure because of the of the compilation and, the types. You know, creating middleware is is very easy and go chaining middleware. We did we we have we have solved that problem. This this is this is not where this is not where you would you would lose time building this hypothetical, invoicing software. So how can we how can we how can we make the database a little bit more interesting?

Dominic:

So without entering too much of the ORM because I don't believe that there's too many people found of that. And, I I really like SQL. Don't don't get me wrong. I'm I'm the first one that will always choose SQL. I've been I've been writing SQL, you know, for for 2 decades now.

Dominic:

That that's not that's not the problem for me. But but, yes. I mean, we it it would be nice to find something. And I've I've seen, I've seen, Ent, you know, e n t. Recently.

Dominic:

Which seems to be, you know, n for it it stands for entity. So it seems to be like an an ORM for Go. But I I think it's built on on on Java and things like that. I don't I don't really know yet. But, that that seems to be that seems to be something that be be be because the thing that I like with the Django ORM or at least the approach that I was kind of starting to think to replicate in Go was you start from a model and the migration are just based on the changes that you apply to that to that model.

Dominic:

So if you have a new field or if you change a field, a field type and things like that, you just generate some some migration and and and that's mostly it. I I find it this part I find it very elegant. Because yeah. My migration are are are not, you know, not very fun in Go as well. So that was fun, you know, in in Python, Django when when you when you just open your your model dot py and you just change something or you add a field and boom that that's done.

Dominic:

You know, I think I think it might be very interesting to see if if something like that can be done. So even even if it would be a common line that I don't know, that read the the the the all the packages in in the current directory and, you know, search for a certain file. You know, this is something that I I I kind of started to brainstorm in my head. So maybe maybe we could have, and I I I know that it's not it's not usually acceptable to have a model that Go file in a package, but it could be. And and this tool could monitor that.

Dominic:

Inspect the code in there and generate some migration based on the changes that we would do on the on the type. So, let's say you have a a type client or whatever, a type, invoice. And if, you know, the the command line tool could do some diff, with with the last version that that it that it generates a migration from and just calculate what's what's changed and, and generate some, some migration from that. This to me, this to me sounds sounds fun. Sounds something like I I would choose Go, you know, for a weekend project.

Dominic:

Something something that I I would like to to build and I know that is it is more krud like, but I still very, very like Ghost. I would like to build it and go, but, I mean, at some point, you you cannot you cannot put, twice or or or 3 times the the effort just, just because there's so many things that that needs to be written regarding the database. So I I think I, I kind of went a little bit too far. I I want I wanted to, you know, my fur my first, my first thought was to talk a little bit about, Temple and whatnot, but I I mean it might be, might be related to CRUD a little bit. Why, why I think, Go is is still is still missing some things for me at least to build very quick crowd side project or at least throw away project.

Dominic:

And this might be, this might be something that I will attack in in the next following months. I don't know. I I I I appreciate go too much and I would I would I'm kind of regretting now 3 months, 4 months later to have written those 2 application in the in Django to be frank. So maybe it's up to me to, to to bring a package to, to the community that that is attacking the the problem differently than what Temple is doing. In my opinion, I would still like to edit my HTML in HTML file.

Dominic:

I I I I believe that the HTML template is is is good enough, but it needs to be augmented with some with some, you know, decent functionality. And and that's that's main mainly, something that I might do. On that, if you want to, you know, to, to sponsor this, this podcast. I mean, I have 2 course in my website, which the there there's some links in the show notes with direct coupon. So, yes, if you want to, to sponsor this show, this is how to do that.

Dominic:

And on that, I will see you next week.