百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
D

daz

> 前端框架
开源

Golang 中的可组合 HTML 组件

198 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

Golang 中的可组合 HTML 组件

daz

Composable HTML components in Golang

Daz is a "functional" alternative to using templates, and allows for nested components/lists Also enables template-free server-side rendered components with support for nested lists. It is inspired by HyperScript.

A component can be created and used with simple functions:

go
// Example prop for a component
type User struct {
	Name string
	// ...
}

func MyComponent(user User) HTML {
	return H(
		"div",
		Attr{"class": "bg-grey-50"},
		user.Name,
	)
}

func Root() HTML {
	user := User{Name: "Daz"}
	return H("html", MyComponent(user))
}

// And used in a handler:

func Handler(w http.ResponseWriter, r *http.Request) {
	w.Write([]byte(Root()()))
}

Lists can be easily created without needing to embed a range / end in a template:

go
items := []HTML{
	H("li", "item one"),
	H("li", "item two"),
}

element := H("ul", Attr{"class": "bg-grey-50"}, items)

div := H("div", element)

Install

import (
	"github.com/stevelacy/daz"
)

Usage

func H

Create a HTML element:

go
H("div", ...attrs)

struct Attr

HTML attributes:

go
Attr{
	"class": "app",
	"onClick": "javascriptFunc()",
}

func UnsafeContent

This will bypass HTML sanitization and allow for direct injecting

go

injection := "
"
root := H("div", UnsafeContent(injection))
// 

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Gocomponentsgolanghtmltemplate

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架