fix(conventions): alias stdlib io, add interface checks, use go-log
All checks were successful
Security Scan / security (push) Successful in 7s
Test / test (push) Successful in 1m34s

- Alias stdlib `io` as `goio` in cmd/codegen/main.go to follow project conventions
- Add compile-time Node interface checks for all node types in node.go
  and Layout in layout.go
- Replace fmt.Fprintf stderr logging with go-log in cmd/codegen/main.go
- Replace fmt.Println with go-log in cmd/wasm/register.go

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Snider 2026-03-15 16:40:39 +00:00
parent 176ef74dfd
commit 2d16ce9d69
6 changed files with 26 additions and 6 deletions

View file

@ -9,14 +9,15 @@ package main
import (
"encoding/json"
"fmt"
"io"
goio "io"
"os"
"forge.lthn.ai/core/go-html/codegen"
log "forge.lthn.ai/core/go-log"
)
func run(r io.Reader, w io.Writer) error {
data, err := io.ReadAll(r)
func run(r goio.Reader, w goio.Writer) error {
data, err := goio.ReadAll(r)
if err != nil {
return fmt.Errorf("codegen: reading stdin: %w", err)
}
@ -31,13 +32,13 @@ func run(r io.Reader, w io.Writer) error {
return err
}
_, err = io.WriteString(w, js)
_, err = goio.WriteString(w, js)
return err
}
func main() {
if err := run(os.Stdin, os.Stdout); err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
log.Error("codegen failed", "err", err)
os.Exit(1)
}
}

View file

@ -7,6 +7,7 @@ import (
"fmt"
"forge.lthn.ai/core/go-html/codegen"
log "forge.lthn.ai/core/go-log"
)
// buildComponentJS takes a JSON slot map and returns the WC bundle JS string.
@ -22,5 +23,5 @@ func buildComponentJS(slotsJSON string) (string, error) {
}
func main() {
fmt.Println("go-html WASM module — build with GOOS=js GOARCH=wasm")
log.Info("go-html WASM module — build with GOOS=js GOARCH=wasm")
}

1
go.mod
View file

@ -4,6 +4,7 @@ go 1.26.0
require (
forge.lthn.ai/core/go-i18n v0.1.4
forge.lthn.ai/core/go-log v0.0.4
github.com/stretchr/testify v1.11.1
)

2
go.sum
View file

@ -2,6 +2,8 @@ forge.lthn.ai/core/go-i18n v0.1.4 h1:zOHUUJDgRo88/3tj++kN+VELg/buyZ4T2OSdG3HBbLQ
forge.lthn.ai/core/go-i18n v0.1.4/go.mod h1:aDyAfz7MMgWYgLkZCptfFmZ7jJg3ocwjEJ1WkJSvv4U=
forge.lthn.ai/core/go-inference v0.1.4 h1:fuAgWbqsEDajHniqAKyvHYbRcBrkGEiGSqR2pfTMRY0=
forge.lthn.ai/core/go-inference v0.1.4/go.mod h1:jfWz+IJX55wAH98+ic6FEqqGB6/P31CHlg7VY7pxREw=
forge.lthn.ai/core/go-log v0.0.4 h1:KTuCEPgFmuM8KJfnyQ8vPOU1Jg654W74h8IJvfQMfv0=
forge.lthn.ai/core/go-log v0.0.4/go.mod h1:r14MXKOD3LF/sI8XUJQhRk/SZHBE7jAFVuCfgkXoZPw=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=

View file

@ -2,6 +2,9 @@ package html
import "strings"
// Compile-time interface check.
var _ Node = (*Layout)(nil)
// slotMeta holds the semantic HTML mapping for each HLCRF slot.
type slotMeta struct {
tag string

12
node.go
View file

@ -15,6 +15,18 @@ type Node interface {
Render(ctx *Context) string
}
// Compile-time interface checks.
var (
_ Node = (*rawNode)(nil)
_ Node = (*elNode)(nil)
_ Node = (*textNode)(nil)
_ Node = (*ifNode)(nil)
_ Node = (*unlessNode)(nil)
_ Node = (*entitledNode)(nil)
_ Node = (*switchNode)(nil)
_ Node = (*eachNode[any])(nil)
)
// voidElements is the set of HTML elements that must not have a closing tag.
var voidElements = map[string]bool{
"area": true,