refactor(conventions): replace os.ReadFile with coreio.Local, fmt.Errorf with log.E
Replace os.ReadFile in cmd/wasm/size_test.go with coreio.Local.Read(). Replace fmt.Errorf/errors.New with log.E() in codegen, cmd/wasm/register, and cmd/codegen. Add forge.lthn.ai/core/go-io as a dependency. Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
2d16ce9d69
commit
6e59bf8bf8
6 changed files with 13 additions and 8 deletions
|
|
@ -8,7 +8,6 @@ package main
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
goio "io"
|
||||
"os"
|
||||
|
||||
|
|
@ -19,12 +18,12 @@ import (
|
|||
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)
|
||||
return log.E("codegen", "reading stdin", err)
|
||||
}
|
||||
|
||||
var slots map[string]string
|
||||
if err := json.Unmarshal(data, &slots); err != nil {
|
||||
return fmt.Errorf("codegen: invalid JSON: %w", err)
|
||||
return log.E("codegen", "invalid JSON", err)
|
||||
}
|
||||
|
||||
js, err := codegen.GenerateBundle(slots)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ package main
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"forge.lthn.ai/core/go-html/codegen"
|
||||
log "forge.lthn.ai/core/go-log"
|
||||
|
|
@ -17,7 +16,7 @@ import (
|
|||
func buildComponentJS(slotsJSON string) (string, error) {
|
||||
var slots map[string]string
|
||||
if err := json.Unmarshal([]byte(slotsJSON), &slots); err != nil {
|
||||
return "", fmt.Errorf("registerComponents: %w", err)
|
||||
return "", log.E("buildComponentJS", "unmarshal JSON", err)
|
||||
}
|
||||
return codegen.GenerateBundle(slots)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import (
|
|||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
coreio "forge.lthn.ai/core/go-io"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
|
@ -33,8 +34,9 @@ func TestWASMBinarySize_Good(t *testing.T) {
|
|||
output, err := cmd.CombinedOutput()
|
||||
require.NoError(t, err, "WASM build failed: %s", output)
|
||||
|
||||
raw, err := os.ReadFile(out)
|
||||
rawStr, err := coreio.Local.Read(out)
|
||||
require.NoError(t, err)
|
||||
raw := []byte(rawStr)
|
||||
|
||||
var buf bytes.Buffer
|
||||
gz, err := gzip.NewWriterLevel(&buf, gzip.BestCompression)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
log "forge.lthn.ai/core/go-log"
|
||||
)
|
||||
|
||||
// wcTemplate is the Web Component class template.
|
||||
|
|
@ -31,7 +33,7 @@ var wcTemplate = template.Must(template.New("wc").Parse(`class {{.ClassName}} ex
|
|||
// GenerateClass produces a JS class definition for a custom element.
|
||||
func GenerateClass(tag, slot string) (string, error) {
|
||||
if !strings.Contains(tag, "-") {
|
||||
return "", fmt.Errorf("codegen: custom element tag %q must contain a hyphen", tag)
|
||||
return "", log.E("codegen.GenerateClass", "custom element tag must contain a hyphen: "+tag, nil)
|
||||
}
|
||||
var b strings.Builder
|
||||
err := wcTemplate.Execute(&b, struct {
|
||||
|
|
@ -42,7 +44,7 @@ func GenerateClass(tag, slot string) (string, error) {
|
|||
Slot: slot,
|
||||
})
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("codegen: template exec: %w", err)
|
||||
return "", log.E("codegen.GenerateClass", "template exec", err)
|
||||
}
|
||||
return b.String(), nil
|
||||
}
|
||||
|
|
|
|||
1
go.mod
1
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-io v0.1.2
|
||||
forge.lthn.ai/core/go-log v0.0.4
|
||||
github.com/stretchr/testify v1.11.1
|
||||
)
|
||||
|
|
|
|||
2
go.sum
2
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-io v0.1.2 h1:q8hj2jtOFqAgHlBr5wsUAOXtaFkxy9gqGrQT/il0WYA=
|
||||
forge.lthn.ai/core/go-io v0.1.2/go.mod h1:PbNKW1Q25ywSOoQXeGdQHbV5aiIrTXvHIQ5uhplA//g=
|
||||
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=
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue