__________ _________ ___________
/ ____/ __ \/_ __/ | / ____/ ___/
/ / __/ / / / / / / /| |/ / __ \__ \
/ /_/ / /_/ / / / / ___ / /_/ /___/ /
\____/\____/ /_/ /_/ |_\____//____/
Template-less. Type-Safe. Simple. Familiar. Pure Go.
- Compose reusable HTML with pure functions
func Card(content ...HTML) HTML {
return Div(
X.Class("card bg-base-100 w-96"),
content,
)
}-
Tags accept
any: strings are automatically wrapped as text nodes, while other Go values panic immediately so problems surface early instead of silently failing. If you need raw HTML, useRaw; plain strings (orTextcomponents) are automatically escaped -
Attributes are accessed through the
Xvalue to make them immediately recognizable and easy to skim -
Compose multiple root components with
Fragmentwhen you need to return more than one component without introducing a wrapper tag or a fullDoc.Fragmentconcatenates its child components in order. It is especially useful for HTTP responses (for example with htmx) where a single response must include multiple independent elements
return Fragment(
H1("Settings"),
Form(
Input(X.Type("text"), X.Name("email")),
Button("Save"),
),
)- Conditional composition with
If(for components) andX.If(for attributes)
button := Button(
X.Class(
"btn",
X.If(isPrimary, "btn-primary"),
X.If(!isPrimary, "btn-secondary"),
),
If(isPrimary, customIcon()),
"Save changes",
)- List of components via
Range - Mutate tags in place with
AddToTag(Helpful when using htmx with swap-oob) - Build custom tags directly with
NewTagComponentwhen you need a tag outside the built-in set
func XMLFeed(content ...HTML) HTML {
// An XML-like root for a feed export.
return NewTagComponent("feed", false, content...)
}- Build custom attributes
func HxGet(value string) HTML {
return X.Attr("hx-get", value)
}- Built-in htmx integration via the
htmxpackage, which provides strongly-typed helpers for all common htmx attributes and headers
import hx "github.com/namzug16/gotags/htmx"
button := Button(
hx.Post("/save"),
hx.On("click", "console.log('saving')"),
"Save",
)go get github.com/namzug16/gotagspackage main
import (
"fmt"
. "github.com/namzug16/gotags"
)
func main() {
isSignedIn := true
users := []string{"Federica", "Mateo", "Ciro"}
page := Doc(
Head(
Title("gotags example"),
Link(X.Rel("stylesheet"), X.Href("/styles.css")),
),
Body(
Header(
H1("Team dashboard"),
Nav(
Ul(
Li(A(X.Href("/"), "Home")),
Li(A(X.Href("/projects"), "Projects")),
Li(A(X.Href("/profile"), If(isSignedIn, Text("Profile")))),
),
),
),
Main(
Section(
H2("People"),
Ul(
Range(users, func(_ int, user string) HTML {
return Li(
X.Class("person", X.If(user == "Ciro", "highlight")),
user,
)
}),
),
),
),
),
)
fmt.Println(page.String())
}