More Premium Hugo Themes Premium Html Themes

Gomponents

HTML components in pure Go.

Gomponents

HTML components in pure Go.

Author Avatar Theme by maragudk
Github Stars Github Stars: 1557
Last Commit Last Commit: May 23, 2025 -
First Commit Created: May 5, 2023 -
default image

Overview:

gomponents is a Go library that allows developers to build reusable view components in pure Go, without the need for complex template languages. It aims to simplify the process of building HTML5 components, allowing developers to focus on creating their applications instead of learning new templating languages. The library provides a simple API that is easy to learn and use, and includes helpful features such as type safety, auto-completion, and useful helpers for rendering text, mapping data to components, and conditional rendering. gomponents is made by maragu, the creator of online Go courses.

Features:

  • Write reusable view components in pure Go
  • Write declarative HTML5 in Go without using strings
  • Provides type safety and auto-completion
  • Simple API that is easy to learn and use
  • Helpful helpers like Text and Textf for inserting HTML-escaped text, Map for mapping data to components, and If for conditional rendering
  • No external dependencies

Installation:

To use gomponents, you can get the library using the go get command:

go get github.com/maragu/gomponents

The preferred way to use gomponents is with dot-imports, which give a smooth, native HTML feel. Here’s an example:

import (
   . "github.com/maragu/gomponents/html"
)

func main() {
   // code using gomponents
}

If you prefer not to use dot-imports, you can use regular imports:

import (
   "github.com/maragu/gomponents/html"
)

func main() {
   // code using gomponents
}

You can also use the provided HTML5 document template to simplify your code:

import (
   . "github.com/maragu/gomponents/html"
   "html/template"
)

func main() {
   // code using gomponents with HTML5 template
}

For more complete examples, you can refer to the examples directory in the gomponents repository.

Summary:

gomponents is a Go library that simplifies the process of building reusable view components in pure Go without relying on complex template languages. It provides a simple API, type safety, and helpful helpers for rendering HTML5 components. With gomponents, developers can focus on building their applications instead of learning new templating languages. The library is easy to install and use, and has no external dependencies. It is created by maragu, the maker of online Go courses.