A Go package to write HTML5 and HTMX components in Go. The package is designed to work with fiber and htmx.
- Write declartive HTML5 components in Go without using templates and with the full-power of a type-safe language, auto-completion, and refactoring.
- Full support for HTMX components.
- No dependencies on JavaScript frameworks.
- Fast rendering of HTML5 and HTMX components.
- Easy to use and learn.
- Easy to extend and customize.
Creating a button leveraging htmx is as easy as this.
htmx.Button(
htmx.Attribute("type", "submit")
htmx.Text("Button"),
htmx.HxPost("/api/respond")
)
$ go get github.com/zeiss/fiber-htmx
There are additional components that help to write HTML5 and HTMX components in Go.
There is also the option to use htmx.Controller
to encapsulate the logic of the components.
type HelloWorldController struct {
htmx.DefaultController
}
func (c *HelloWorldController) Get() error {
return htmx.RenderComp(
c.Ctx(),
htmx.HTML5(
htmx.HTML5Props{
Title: "index",
Language: "en",
Head: []htmx.Node{},
},
htmx.Div(
htmx.ClassNames{},
htmx.Text("Hello World"),
),
),
)
}
app := fiber.New()
app.Get("/", htmx.NewHxControllerHandler(&HelloWorldController{}))
app.Listen(":3000")
See examples to understand the provided interfaces.
BenchmarkElement-2 7863930 132.8 ns/op
BenchmarkAttribute-2 8052403 157.9 ns/op
Benchmark_HTML5_Render-2 788 1596065 ns/op
Rendering 10.000
nodes took >1.6ms
. The package is fast enough to render HTML5 and HTMX components.