Golang + HTMX - Creating a Go webserver / HTMX Integration / Template Fragments

preview_player
Показать описание

In this video, we'll explore how to integrate HTMX with the Go programming language on the server.

We'll cover:
- how to setup a webserver with the Go net/http package
- how to define routes and handlers with the HandleFunc function
- how to return HTML templates with the html/template package
- using HTMX to submit form data to the server
- swapping HTML responses into the document from our Golang handlers
- using template fragments to return blocks of HTML from a parent template

Final code can be found on this Github repository:

☕️ 𝗕𝘂𝘆 𝗺𝗲 𝗮 𝗰𝗼𝗳𝗳𝗲𝗲:
To support the channel and encourage new videos, please consider buying me a coffee here:

Playlist ▶️:

📌 𝗖𝗵𝗮𝗽𝘁𝗲𝗿𝘀:
00:00 Intro
01:32 Creating a web server in Golang
03:28 Defining server URL and handler function with http.HandleFunc
06:31 Rendering template from Golang functions
09:40 Adding Context Data to templates
11:21 Displaying server data in templates
13:44 Styling list with Bootstrap 5
15:34 Submitting form with HTMX hx-post attribute
19:44 Extract Submitted Data from POST request in handler function
21:03 Returning HTML from Golang handler function
24:03 Using hx-target to swap content into targeted DOM element
26:51 Displaying feedback during request with hx-indicator
30:37 Template Fragments in Golang

𝗦𝗼𝗰𝗶𝗮𝗹 𝗠𝗲𝗱𝗶𝗮:

📚 𝗙𝘂𝗿𝘁𝗵𝗲𝗿 𝗿𝗲𝗮𝗱𝗶𝗻𝗴 𝗮𝗻𝗱 𝗶𝗻𝗳𝗼𝗿𝗺𝗮𝘁𝗶𝗼𝗻:

#golang #htmx #webdevelopment
Рекомендации по теме
Комментарии
Автор

I would love to see a bigger project with HTMX + GOLANG that uses databases, great content man!

elhaambasheerch
Автор

This is one of the most concise and straight to the point tutorials on Go + HTMX and templating on YouTube!

geoblk
Автор

Thanks a lot! Very cool video. I'm just dealing with a bunch of GO and HTMX! Looking forward to more videos on this topic! You're doing great!

qsvsgbz
Автор

I appreciate that you explained certain terms or concepts in relation to Django. It really helps put things in perspective. This is one of the most understandble Go video I've seen. Thank you. I hope to see more. Especially with something along Fiber + GORM. Because from my readings that are the nearest combination to Django.

FirdausAziz
Автор

I'm new to Go and HTMX. The majority of the time I work with React/Node.js project. I was looking for a quick overview of these technologies. This video is exactly what I was looking for. In my opinion, it's a great intro. Thanks! Looking forward to seeing more advanced videos.

benderino
Автор

Love your way of teaching! Straight to the point, but going step by step, and doing everything by hand, rather than pasting blocks of code. Congratulations!

darthcabs
Автор

This video is a master piece. I watched it a week ago with little knowledge of HTMX and no knowledge of GO templates. After learning more about the two subjects, I saw this video again and it is great! Thx a lot! Really good job!

ZorroRBF
Автор

This seems like an awesome introduction to both golang and HTMX - can’t wait to try this!

catcatcatcatcatcatcatcatcatca
Автор

Thanks! I started checking HTMX with Go just an hour ago and surprisingly found your video that is published 16 hours ago. I am lucky. Though htmx itself was easy, you made that surely easier :) Thanks again.

ahmettek
Автор

Great content! Your django+htmx content has helped me building an interactive web app for a national hospital without the need of JS frontend framework. It is currently used by the hospital and I am still enriching or improving the web app bit by bit. Now with GO, really helps me to learn new PL with different perspectives and approaches to tackle some of the Python issues. Would love to see more GO contents. Thanks a million.

mentotong
Автор

A great video! Clear, concise, and helpful! Looking forward to the series!

dareason
Автор

This was such a great video! Appreciate the thorough and straightforward explanation as we went along. Interested in more Go content. Keep up the great work.

baz
Автор

12:20 Btw, if you guys happen to be iterating over an array, you must use {{ . }}

That means that it would just use the data as is. If you send a slice, say "Slice": { "hello", "world"}

it should be something like this

{{ range .Slice }}
<p> {{.}} </p>
{{end}}

that should print hello and world in separated lines.

I suppose that's also why you use .Slice, because you send a map, so the point represents that particular map.

Also, I don't know if that changed, but right now hot reloading works, so it's not neccesary to restart the server everytime you make a change.

This is a beautiful and fast tutorial. Thank you so much, and also thank you for sharing the links for learning further.

maximofernandez
Автор

HTMX + Go series is absolutely necessary

Subbed 🙌

avithedev
Автор

Stopped at 6:38 to say how excellent this video is, from a beginner's perspective.

speedTurtle
Автор

Just got started with Golang & HTMX
Thanks for the great content, perfect demo project for beginners!

benyaminyakobi
Автор

More such Go tutorials appreciated. Also, group GO tutorials into a playlist like you've created for Python.

anujtyagi
Автор

You are constantly anticipating what I want to learn. This is great.

willdurant
Автор

Great video, thanks for sharing. Be aware that the method used at 21:45 won't escape user inputs, so isn't safe for use in production. The html/template package does automatically escape though, so you can just use a template and parse the data.

nodidog
Автор

Amazing content man. Really looking forward to a bigger project tutorial of Go + HTMX, maybe with some ORMs and migrations? Thanks for your efforts!

fersalamanca
visit shbcf.ru