gotags

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2026 License: MIT Imports: 3 Imported by: 0

README

GoDoc Go Report Card

   __________  _________   ___________
  / ____/ __ \/_  __/   | / ____/ ___/
 / / __/ / / / / / / /| |/ / __ \__ \ 
/ /_/ / /_/ / / / / ___ / /_/ /___/ / 
\____/\____/ /_/ /_/  |_\____//____/  

Template-less. Type-Safe. Simple. Familiar. Pure Go.

Features

  • 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, use Raw; plain strings (or Text components) are automatically escaped

  • Attributes are accessed through the X value to make them immediately recognizable and easy to skim

  • Compose multiple root components with Fragment when you need to return more than one component without introducing a wrapper tag or a full Doc. Fragment concatenates 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) and X.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 NewTagComponent when 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 htmx package, 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",
)

Usage

go get github.com/namzug16/gotags
package 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())
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var X = attrs{}

Defines attributes

Functions

This section is empty.

Types

type AttributeComponent

type AttributeComponent struct {
	// contains filtered or unexported fields
}

func (*AttributeComponent) String

func (a *AttributeComponent) String() string

type DocComponent

type DocComponent struct {
	Components []HTML
}

func Doc

func Doc(components ...HTML) *DocComponent

func (*DocComponent) String

func (d *DocComponent) String() string

type FragmentComponent

type FragmentComponent struct {
	// contains filtered or unexported fields
}

func Fragment

func Fragment(components ...any) *FragmentComponent

func (*FragmentComponent) String

func (f *FragmentComponent) String() string

type HTML

type HTML interface {
	String() string
}

func A

func A(content ...any) HTML

func Abbr

func Abbr(content ...any) HTML

func AddToTag

func AddToTag(target HTML, components ...HTML) HTML

func Address

func Address(content ...any) HTML

func Area

func Area(content ...any) HTML

func Article

func Article(content ...any) HTML

func Aside

func Aside(content ...any) HTML

func Audio

func Audio(content ...any) HTML

func B

func B(content ...any) HTML

func Base

func Base(content ...any) HTML

func Bdi

func Bdi(content ...any) HTML

func Bdo

func Bdo(content ...any) HTML

func Blockquote

func Blockquote(content ...any) HTML

func Body

func Body(content ...any) HTML

func Br

func Br(content ...any) HTML

func Button

func Button(content ...any) HTML

func Canvas

func Canvas(content ...any) HTML

func Caption

func Caption(content ...any) HTML

func Cite

func Cite(content ...any) HTML

func Code

func Code(content ...any) HTML

func Col

func Col(content ...any) HTML

func Colgroup

func Colgroup(content ...any) HTML

func Data

func Data(content ...any) HTML

func Datalist

func Datalist(content ...any) HTML

func Dd

func Dd(content ...any) HTML

func Del

func Del(content ...any) HTML

func Details

func Details(content ...any) HTML

func Dfn

func Dfn(content ...any) HTML

func Dialog

func Dialog(content ...any) HTML

func Div

func Div(content ...any) HTML

func Dl

func Dl(content ...any) HTML

func Dt

func Dt(content ...any) HTML

func Em

func Em(content ...any) HTML

func Embed

func Embed(content ...any) HTML

func Fencedframe

func Fencedframe(content ...any) HTML

func Fieldset

func Fieldset(content ...any) HTML

func Figcaption

func Figcaption(content ...any) HTML

func Figure

func Figure(content ...any) HTML
func Footer(content ...any) HTML

func Form

func Form(content ...any) HTML

func H1

func H1(content ...any) HTML

func H2

func H2(content ...any) HTML

func H3

func H3(content ...any) HTML

func H4

func H4(content ...any) HTML

func H5

func H5(content ...any) HTML

func H6

func H6(content ...any) HTML
func Head(content ...any) HTML
func Header(content ...any) HTML

func Hgroup

func Hgroup(content ...any) HTML

func Hr

func Hr(content ...any) HTML

func I

func I(content ...any) HTML

func If

func If(condition bool, components ...any) []HTML

func IfLazy added in v0.3.0

func IfLazy(condition bool, component func() HTML) HTML

func Iframe

func Iframe(content ...any) HTML

func Img

func Img(content ...any) HTML

func Input

func Input(content ...any) HTML

func Ins

func Ins(content ...any) HTML

func Kbd

func Kbd(content ...any) HTML

func Label

func Label(content ...any) HTML

func Legend

func Legend(content ...any) HTML

func Li

func Li(content ...any) HTML
func Link(content ...any) HTML

func Main

func Main(content ...any) HTML

func Map

func Map(content ...any) HTML

func Mark

func Mark(content ...any) HTML

func Math

func Math(content ...any) HTML
func Menu(content ...any) HTML

func Meta

func Meta(content ...any) HTML

func Meter

func Meter(content ...any) HTML
func Nav(content ...any) HTML

func Noscript

func Noscript(content ...any) HTML

func Object

func Object(content ...any) HTML

func Ol

func Ol(content ...any) HTML

func Optgroup

func Optgroup(content ...any) HTML

func Option

func Option(content ...any) HTML

func Output

func Output(content ...any) HTML

func P

func P(content ...any) HTML

func Picture

func Picture(content ...any) HTML

func Pre

func Pre(content ...any) HTML

func Progress

func Progress(content ...any) HTML

func Q

func Q(content ...any) HTML

func Range

func Range[T any](items []T, toComponent func(int, T) HTML) []HTML

func Rp

func Rp(content ...any) HTML

func Rt

func Rt(content ...any) HTML

func Ruby

func Ruby(content ...any) HTML

func S

func S(content ...any) HTML

func Samp

func Samp(content ...any) HTML

func Script

func Script(content ...any) HTML
func Search(content ...any) HTML

func Section

func Section(content ...any) HTML

func Select

func Select(content ...any) HTML

func Slot

func Slot(content ...any) HTML

func Small

func Small(content ...any) HTML

func Source

func Source(content ...any) HTML

func Span

func Span(content ...any) HTML

func Strong

func Strong(content ...any) HTML

func Style

func Style(content ...any) HTML

func Sub

func Sub(content ...any) HTML

func Summary

func Summary(content ...any) HTML

func Sup

func Sup(content ...any) HTML

func Svg

func Svg(content ...any) HTML

func Table

func Table(content ...any) HTML

func Tbody

func Tbody(content ...any) HTML

func Td

func Td(content ...any) HTML

func Template

func Template(content ...any) HTML

func Textarea

func Textarea(content ...any) HTML

func Tfoot

func Tfoot(content ...any) HTML

func Th

func Th(content ...any) HTML

func Thead

func Thead(content ...any) HTML

func Time

func Time(content ...any) HTML

func Title

func Title(content ...any) HTML

func Tr

func Tr(content ...any) HTML

func Track

func Track(content ...any) HTML

func U

func U(content ...any) HTML

func Ul

func Ul(content ...any) HTML

func Var

func Var(content ...any) HTML

func Video

func Video(content ...any) HTML

func Wbr

func Wbr(content ...any) HTML

type Raw

type Raw string

func (Raw) String

func (t Raw) String() string

type TagComponent

type TagComponent struct {
	// contains filtered or unexported fields
}

func NewTagComponent

func NewTagComponent(name string, isVoid bool, content ...HTML) *TagComponent

func (*TagComponent) String

func (t *TagComponent) String() string

type Text

type Text string

func (Text) String

func (t Text) String() string

Directories

Path Synopsis
cmd
demo command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL