From 2d16ce9d69c836d8ada078f381698ca09f596d90 Mon Sep 17 00:00:00 2001 From: Snider Date: Sun, 15 Mar 2026 16:40:39 +0000 Subject: [PATCH] fix(conventions): alias stdlib io, add interface checks, use go-log - 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 --- cmd/codegen/main.go | 11 ++++++----- cmd/wasm/register.go | 3 ++- go.mod | 1 + go.sum | 2 ++ layout.go | 3 +++ node.go | 12 ++++++++++++ 6 files changed, 26 insertions(+), 6 deletions(-) diff --git a/cmd/codegen/main.go b/cmd/codegen/main.go index 199c4cb..00f20dc 100644 --- a/cmd/codegen/main.go +++ b/cmd/codegen/main.go @@ -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) } } diff --git a/cmd/wasm/register.go b/cmd/wasm/register.go index d003e32..2146dd0 100644 --- a/cmd/wasm/register.go +++ b/cmd/wasm/register.go @@ -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") } diff --git a/go.mod b/go.mod index cc89be8..c2b1dae 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 0e341a5..e71eb4f 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/layout.go b/layout.go index bc2775c..adf9b88 100644 --- a/layout.go +++ b/layout.go @@ -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 diff --git a/node.go b/node.go index 9416e0e..54a359c 100644 --- a/node.go +++ b/node.go @@ -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,