dom

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: Apache-2.0 Imports: 2 Imported by: 2

README

go-wasmbuild

wasmbuild is a command-line tool for compiling applications from the Go programming language ("golang") into WASM so they can be run as web applications in a browser.

It provides a development environment so you can test your code as you develop it. There are packages for several popular JavaScript libraries, so you can - for example - create reactive web components in golang.

Experimental! Please note this repository contains code which depends on experimental features of the Go language.

This repository provides three main components:

  1. WASM Build Server (cmd/wasmbuild) - A feature-rich development server for building and serving golang WASM applications with live reload, error notifications, and automatic dependency watching
  2. DOM Package (pkg/dom) - A Go implementation of the Document Object Model (DOM) API that works both natively and in WASM environments
  3. Bootstrap 5 Package (pkg/bootstrap) - Go wrappers for Bootstrap 5 components

There are also some examples of developing front-end applications in the wasm folder.

WASM Build Server

The wasmbuild tool provides a modern development experience for WASM applications written in Go. Please see the documentation for wasmbuild for full details.

Example usage:

# Install wasmbuild
go install github.com/djthorpe/go-wasmbuild/cmd/wasmbuild

# Start the wasmbuild server, watch for changes
wasmbuild serve -w path/to/your/go/project

# Navigate to http://localhost:8080 in your browser for development

# Build a production version of your app
wasmbuild build -o ./dist path/to/your/go/project
Features
  • Compile golang to WASM - Seamlessly compiles Go applications to WebAssembly
  • Serve WASM Applications - Hosts your WASM apps with a built-in HTTP server, including serving the bootstrap HTML and JS needed to run Go WASM applications
  • Automatic Dependency Discovery - Watches all local package dependencies (no manual configuration needed)
  • Live Reload - Automatically recompiles and reloads the browser when source files change
  • Real-time Error Display - Compilation errors appear directly in the browser with full error messages

Bootstrap

The pkg/bootstrap package provides Go wrappers for Bootstrap 5 components, allowing you to build Bootstrap-based web applications in Go/WASM. A comprehensive demo application showcasing all components is available in wasm/bootstrap-app.

Bootstrap Components
  • Card-based layouts with headers and footers
  • Navigation bars with dropdowns and color schemes
  • Alerts, badges, buttons with icon support
  • Modals with forms and input groups
  • Accordions, pagination, progress bars
  • Toast notifications, offcanvas panels
  • Tables, tabs, breadcrumbs
  • Responsive grid system (Row/Col)
  • Form controls with validation
  • Bootstrap Icons integration

Running Tests

You can run tests both in the native go environment and in the WASM environment. The commands for testing are:

git clone git@github.com:djthorpe/go-wasmbuild.git
cd go-wasmbuild
# Test in native go environment
make test
# Test in browser environment
make jstest

Testing in a WASM environment uses wasmbrowsertest. Please see the documentation for that package for more information on testing in the WASM environment and browser support.

License

This project is licensed under the Apache License, Version 2.0. The Apache License is a permissive free software license that:

  • Allows commercial use, modification, distribution, and private use
  • Requires preservation of copyright and license notices, and inclusion of a NOTICE file if one exists
  • Provides an express grant of patent rights from contributors to users
  • Does not provide trademark rights or warranties
  • Requires stating significant changes made to the software

For the complete license terms, see the LICENSE file or visit http://www.apache.org/licenses/LICENSE-2.0.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attr

type Attr interface {
	Node

	// Properties
	OwnerElement() Element
	Name() string
	Value() string
	SetValue(string)
}

Attr implements https://developer.mozilla.org/en-US/docs/Web/API/Attr

type Comment

type Comment interface {
	Node

	// Properties
	Data() string
	Length() int
}

Comment implements https://developer.mozilla.org/en-US/docs/Web/API/Comment

type Document

type Document interface {
	EventTarget
	Node

	// Properties
	Head() Element
	Body() Element
	Title() string
	Doctype() DocumentType

	// Methods
	CreateElement(string) Element
	CreateAttribute(string) Attr
	CreateComment(string) Comment
	CreateTextNode(string) Text
}

Document implements https://developer.mozilla.org/en-US/docs/Web/API/Document

type DocumentType

type DocumentType interface {
	Node

	// Properties
	Name() string
	PublicId() string
	SystemId() string
}

Document implements https://developer.mozilla.org/en-US/docs/Web/API/DocumentType

type Element

type Element interface {
	EventTarget
	Node

	// Element properties
	TagName() string
	ID() string
	SetID(string)
	OuterHTML() string
	InnerHTML() string
	SetInnerHTML(string)

	// Classes
	ClassName() string
	SetClassName(string)
	ClassList() TokenList

	// Attributes
	Attributes() []Attr
	RemoveAttribute(string)
	RemoveAttributeNode(Attr)
	SetAttribute(string, string) Attr
	SetAttributeNode(Attr) Attr
	GetAttributeNames() []string
	GetAttribute(string) string
	GetAttributeNode(string) Attr
	HasAttribute(string) bool
	HasAttributes() bool

	// Selection Methods
	GetElementsByClassName(string) []Element
	GetElementsByTagName(string) []Element
	QuerySelector(selector string) Element
	QuerySelectorAll(selector string) []Element

	// DOM Manipulation Methods
	Children() []Element
	ChildElementCount() int
	FirstElementChild() Element
	LastElementChild() Element
	NextElementSibling() Element
	PreviousElementSibling() Element
	ReplaceWith(...Node)
	Remove()
	Prepend(...Node)

	// Data sets or gets the value of the element. In general this operates the same
	// was as Value() except for specific element types like input elements.
	// Radio or checkbox input elements will return a boolean for Data() instead of a string.
	Data() any
	SetData(any)

	// Return the value of the element as a string, or empty string if not applicable
	Value() string
	SetValue(string)
}

Element implements https://developer.mozilla.org/en-US/docs/Web/API/Element

type Error

type Error uint
const (
	ErrSuccess Error = iota
	ErrBadParameter
	ErrDuplicateEntry
	ErrUnexpectedResponse
	ErrNotFound
	ErrNotModified
	ErrInternalAppError
	ErrNotImplemented
)

func (Error) Error

func (e Error) Error() string

func (Error) With

func (e Error) With(args ...any) error

func (Error) Withf

func (e Error) Withf(format string, args ...any) error

type Event

type Event interface {
	// Properties
	Type() string
	Target() any
}

Event implements https://developer.mozilla.org/en-US/docs/Web/API/Event

type EventTarget

type EventTarget interface {
	AddEventListener(string, func(Event))
	RemoveEventListener(string)
	DispatchEvent(Event)
}

EventTarget implements https://developer.mozilla.org/en-US/docs/Web/API/EventTarget

type Location

type Location interface {
	// Properties
	Href() string
	Hash() string
}

Location implements https://developer.mozilla.org/en-US/docs/Web/API/Location

type Node

type Node interface {
	Writer

	// Properties
	ChildNodes() []Node
	Contains(Node) bool
	Equals(Node) bool
	FirstChild() Node
	HasChildNodes() bool
	IsConnected() bool
	LastChild() Node
	NextSibling() Node
	NodeName() string
	NodeType() NodeType
	OwnerDocument() Document
	ParentElement() Element
	ParentNode() Node
	PreviousSibling() Node
	TextContent() string

	// Methods
	AppendChild(Node) Node
	InsertBefore(Node, Node) Node
	RemoveChild(Node)

	// JSValue returns the underlying JavaScript value (WASM only)
	JSValue() any
}

Node implements https://developer.mozilla.org/en-US/docs/Web/API/Node

type NodeType

type NodeType int
const (
	UNKNOWN_NODE NodeType = iota
	ELEMENT_NODE
	ATTRIBUTE_NODE
	TEXT_NODE
	CDATA_SECTION_NODE
	ENTITY_REFERENCE_NODE
	ENTITY_NODE
	PROCESSING_INSTRUCTION_NODE
	COMMENT_NODE
	DOCUMENT_NODE
	DOCUMENT_TYPE_NODE
	DOCUMENT_FRAGMENT_NODE
	NOTATION_NODE
)

func (NodeType) String

func (t NodeType) String() string

type Style

type Style interface {
	// Methods
	Get(string) string
	Set(string, string)
}

Style implements https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleDeclaration

type Text

type Text interface {
	Node

	// Properties
	Data() string
	SetData(string)
	Length() int
}

Text implements https://developer.mozilla.org/en-US/docs/Web/API/Text

type TokenList

type TokenList interface {
	// Properties
	Length() int
	Value() string

	// Methods
	Values() []string
	Contains(string) bool
	Add(...string)
	Remove(...string)
	Toggle(value string, force ...bool) bool
}

TokenList implements https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList

type Window

type Window interface {
	EventTarget

	// Properties
	Document() Document
	Location() Location
}

Window implements https://developer.mozilla.org/en-US/docs/Web/API/Window

type Writer

type Writer interface {
	Write(io.Writer) (int, error)
}

Writer writes the node to an io.Writer

Directories

Path Synopsis
cmd
gen-icons command
gen-icons generates icon_names.go by parsing the icon registry in npm/carbon/icons-generated.js.
gen-icons generates icon_names.go by parsing the icon registry in npm/carbon/icons-generated.js.
wasmbuild command
pkg
dom
js
mvc
Package mvc provides a thin model-view-controller layer for building declarative WASM user interfaces using the go-wasmbuild DOM wrappers.
Package mvc provides a thin model-view-controller layer for building declarative WASM user interfaces using the go-wasmbuild DOM wrappers.
wasm
bart-app command
bootstrap-app command
carbon-app command
helloworld-app command

Jump to

Keyboard shortcuts

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