1.7 KiB
Introduction
htmgo is a lightweight pure go way to build interactive websites / web applications using go & htmx. We give you the utilities to build html using pure go code in a reusable way (go functions are components) while also providing htmx functions to add interactivity to your app.
func DocsPage(ctx *h.RequestContext) *h.Page {
pages := dirwalk.WalkPages("md/docs")
return h.NewPage(
h.Div(
h.Class("flex flex-col md:flex-row gap-4"),
DocSidebar(pages),
h.Div(
h.Class("flex flex-col justify-center items-center mt-6"),
h.List(pages, func(page *dirwalk.Page, index int) *h.Element {
return h.Div(
h.Class("border-b border-b-slate-300"),
MarkdownContent(ctx, page),
)
}),
),
),
)
}
The site you are reading now was written with htmgo!
Quick overview
-
Server side rendered html, deploy as a single binary
-
Built in live reloading
-
Built in support for various libraries such as tailwindcss, htmx
-
Go functions are components, no special syntax necessary to learn
-
Many composable utility functions to streamline development and reduce boilerplate
func ChangeTab(ctx *h.RequestContext) *h.Partial { service := tasks.NewService(ctx.ServiceLocator()) list, _ := service.List() tab := ctx.QueryParam("tab") return h.SwapManyPartialWithHeaders(ctx, h.PushQsHeader(ctx, h.NewQs("tab", tab)), List(list, tab), Footer(list, tab), ) }Example: h.SwapManyPartialWithHeaders to swap out multiple elements on the page with your response, as well as set a new query string parameter.
See #core-concepts for more information.