diff --git a/cli/htmgo/go.mod b/cli/htmgo/go.mod index 7d67f4e..ab25b62 100644 --- a/cli/htmgo/go.mod +++ b/cli/htmgo/go.mod @@ -5,8 +5,8 @@ go 1.23.0 require ( github.com/fsnotify/fsnotify v1.7.0 github.com/google/uuid v1.6.0 - github.com/maddalax/htmgo/framework v1.0.3-0.20241109183230-b234ead96499 - github.com/maddalax/htmgo/tools/html-to-htmgo v0.0.0-20241109183230-b234ead96499 + github.com/maddalax/htmgo/framework v1.0.3-0.20241116145200-825c4dd7ecca + github.com/maddalax/htmgo/tools/html-to-htmgo v0.0.0-20241116145200-825c4dd7ecca github.com/stretchr/testify v1.9.0 golang.org/x/mod v0.21.0 golang.org/x/sys v0.26.0 diff --git a/cli/htmgo/go.sum b/cli/htmgo/go.sum index 5942c25..954a850 100644 --- a/cli/htmgo/go.sum +++ b/cli/htmgo/go.sum @@ -8,10 +8,10 @@ github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw= github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/maddalax/htmgo/framework v1.0.3-0.20241109183230-b234ead96499 h1:hQF++Rt9lJHUFk8PG097MTbpl2NnEcbot0iy8ZVPSOI= -github.com/maddalax/htmgo/framework v1.0.3-0.20241109183230-b234ead96499/go.mod h1:NGGzWVXWksrQJ9kV9SGa/A1F1Bjsgc08cN7ZVb98RqY= -github.com/maddalax/htmgo/tools/html-to-htmgo v0.0.0-20241109183230-b234ead96499 h1:uny6xIIU2zNdP03qhQsdfJDOAQR+EBDtlY0DxzIFeCw= -github.com/maddalax/htmgo/tools/html-to-htmgo v0.0.0-20241109183230-b234ead96499/go.mod h1:FraJsj3NRuLBQDk83ZVa+psbNRNLe+rajVtVhYMEme4= +github.com/maddalax/htmgo/framework v1.0.3-0.20241116145200-825c4dd7ecca h1:XiXldwjy1R6dqh7nr6X0coCu5OyA4WZsXVkayM4f4Tw= +github.com/maddalax/htmgo/framework v1.0.3-0.20241116145200-825c4dd7ecca/go.mod h1:NGGzWVXWksrQJ9kV9SGa/A1F1Bjsgc08cN7ZVb98RqY= +github.com/maddalax/htmgo/tools/html-to-htmgo v0.0.0-20241116145200-825c4dd7ecca h1:yAs6jEsQjQ/Dg47DA0clJ3rgzxvjCS+lQk5NovRx0WQ= +github.com/maddalax/htmgo/tools/html-to-htmgo v0.0.0-20241116145200-825c4dd7ecca/go.mod h1:FraJsj3NRuLBQDk83ZVa+psbNRNLe+rajVtVhYMEme4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= diff --git a/cli/htmgo/tasks/astgen/entry.go b/cli/htmgo/tasks/astgen/entry.go index 359f39e..8e7e458 100644 --- a/cli/htmgo/tasks/astgen/entry.go +++ b/cli/htmgo/tasks/astgen/entry.go @@ -2,13 +2,9 @@ package astgen import ( "fmt" - "github.com/maddalax/htmgo/cli/htmgo/internal/dirutil" - "github.com/maddalax/htmgo/cli/htmgo/tasks/process" - "github.com/maddalax/htmgo/framework/h" "go/ast" "go/parser" "go/token" - "golang.org/x/mod/modfile" "io/fs" "log/slog" "os" @@ -16,6 +12,11 @@ import ( "slices" "strings" "unicode" + + "github.com/maddalax/htmgo/cli/htmgo/internal/dirutil" + "github.com/maddalax/htmgo/cli/htmgo/tasks/process" + "github.com/maddalax/htmgo/framework/h" + "golang.org/x/mod/modfile" ) type Page struct { @@ -483,9 +484,36 @@ func writeAssetsFile() { } +func HasModuleFile(path string) bool { + _, err := os.Stat(path) + return !os.IsNotExist(err) +} + +func CheckPagesDirectory(path string) error { + pagesPath := filepath.Join(path, "pages") + _, err := os.Stat(pagesPath) + if err != nil { + return fmt.Errorf("The directory pages does not exist.") + } + + return nil +} + func GetModuleName() string { wd := process.GetWorkingDir() modPath := filepath.Join(wd, "go.mod") + + if HasModuleFile(modPath) == false { + fmt.Fprintf(os.Stderr, "Module not found: go.mod file does not exist.") + return "" + } + + checkDir := CheckPagesDirectory(wd) + if checkDir != nil { + fmt.Fprintf(os.Stderr, checkDir.Error()) + return "" + } + goModBytes, err := os.ReadFile(modPath) if err != nil { fmt.Fprintf(os.Stderr, "error reading go.mod: %v\n", err) diff --git a/cli/htmgo/tasks/astgen/project-sample/go.mod b/cli/htmgo/tasks/astgen/project-sample/go.mod index 981c812..e0f3622 100644 --- a/cli/htmgo/tasks/astgen/project-sample/go.mod +++ b/cli/htmgo/tasks/astgen/project-sample/go.mod @@ -2,12 +2,10 @@ module astgen-project-sample go 1.23.0 -require ( - github.com/go-chi/chi/v5 v5.1.0 - github.com/maddalax/htmgo/framework v1.0.3-0.20241109183230-b234ead96499 -) +require github.com/maddalax/htmgo/framework v1.0.3-0.20241116145200-825c4dd7ecca require ( + github.com/go-chi/chi/v5 v5.1.0 // indirect github.com/google/uuid v1.6.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/cli/htmgo/tasks/astgen/project-sample/go.sum b/cli/htmgo/tasks/astgen/project-sample/go.sum index bbed914..2d58c3e 100644 --- a/cli/htmgo/tasks/astgen/project-sample/go.sum +++ b/cli/htmgo/tasks/astgen/project-sample/go.sum @@ -4,8 +4,8 @@ github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw= github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/maddalax/htmgo/framework v1.0.3-0.20241109183230-b234ead96499 h1:hQF++Rt9lJHUFk8PG097MTbpl2NnEcbot0iy8ZVPSOI= -github.com/maddalax/htmgo/framework v1.0.3-0.20241109183230-b234ead96499/go.mod h1:NGGzWVXWksrQJ9kV9SGa/A1F1Bjsgc08cN7ZVb98RqY= +github.com/maddalax/htmgo/framework v1.0.3-0.20241116145200-825c4dd7ecca h1:XiXldwjy1R6dqh7nr6X0coCu5OyA4WZsXVkayM4f4Tw= +github.com/maddalax/htmgo/framework v1.0.3-0.20241116145200-825c4dd7ecca/go.mod h1:NGGzWVXWksrQJ9kV9SGa/A1F1Bjsgc08cN7ZVb98RqY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= diff --git a/examples/chat/go.mod b/examples/chat/go.mod index 71fc64d..be4236b 100644 --- a/examples/chat/go.mod +++ b/examples/chat/go.mod @@ -5,7 +5,7 @@ go 1.23.0 require ( github.com/go-chi/chi/v5 v5.1.0 github.com/google/uuid v1.6.0 - github.com/maddalax/htmgo/framework v1.0.3-0.20241109183230-b234ead96499 + github.com/maddalax/htmgo/framework v1.0.3-0.20241116145200-825c4dd7ecca github.com/mattn/go-sqlite3 v1.14.23 github.com/puzpuzpuz/xsync/v3 v3.4.0 ) diff --git a/examples/chat/go.sum b/examples/chat/go.sum index 4670ba1..32efb60 100644 --- a/examples/chat/go.sum +++ b/examples/chat/go.sum @@ -4,8 +4,8 @@ github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw= github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/maddalax/htmgo/framework v1.0.3-0.20241109183230-b234ead96499 h1:hQF++Rt9lJHUFk8PG097MTbpl2NnEcbot0iy8ZVPSOI= -github.com/maddalax/htmgo/framework v1.0.3-0.20241109183230-b234ead96499/go.mod h1:NGGzWVXWksrQJ9kV9SGa/A1F1Bjsgc08cN7ZVb98RqY= +github.com/maddalax/htmgo/framework v1.0.3-0.20241116145200-825c4dd7ecca h1:XiXldwjy1R6dqh7nr6X0coCu5OyA4WZsXVkayM4f4Tw= +github.com/maddalax/htmgo/framework v1.0.3-0.20241116145200-825c4dd7ecca/go.mod h1:NGGzWVXWksrQJ9kV9SGa/A1F1Bjsgc08cN7ZVb98RqY= github.com/mattn/go-sqlite3 v1.14.23 h1:gbShiuAP1W5j9UOksQ06aiiqPMxYecovVGwmTxWtuw0= github.com/mattn/go-sqlite3 v1.14.23/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/examples/hackernews/go.mod b/examples/hackernews/go.mod index f2a754a..1aca14c 100644 --- a/examples/hackernews/go.mod +++ b/examples/hackernews/go.mod @@ -3,7 +3,7 @@ module hackernews go 1.23.0 require ( - github.com/maddalax/htmgo/framework v1.0.3-0.20241109183230-b234ead96499 + github.com/maddalax/htmgo/framework v1.0.3-0.20241116145200-825c4dd7ecca github.com/microcosm-cc/bluemonday v1.0.27 ) diff --git a/examples/hackernews/go.sum b/examples/hackernews/go.sum index a3db1b9..6c4c88d 100644 --- a/examples/hackernews/go.sum +++ b/examples/hackernews/go.sum @@ -8,8 +8,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8= github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0= -github.com/maddalax/htmgo/framework v1.0.3-0.20241109183230-b234ead96499 h1:hQF++Rt9lJHUFk8PG097MTbpl2NnEcbot0iy8ZVPSOI= -github.com/maddalax/htmgo/framework v1.0.3-0.20241109183230-b234ead96499/go.mod h1:NGGzWVXWksrQJ9kV9SGa/A1F1Bjsgc08cN7ZVb98RqY= +github.com/maddalax/htmgo/framework v1.0.3-0.20241116145200-825c4dd7ecca h1:XiXldwjy1R6dqh7nr6X0coCu5OyA4WZsXVkayM4f4Tw= +github.com/maddalax/htmgo/framework v1.0.3-0.20241116145200-825c4dd7ecca/go.mod h1:NGGzWVXWksrQJ9kV9SGa/A1F1Bjsgc08cN7ZVb98RqY= github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwXFM08ygZfk= github.com/microcosm-cc/bluemonday v1.0.27/go.mod h1:jFi9vgW+H7c3V0lb6nR74Ib/DIB5OBs92Dimizgw2cA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/examples/simple-auth/go.mod b/examples/simple-auth/go.mod index b48a17f..d5fb4d9 100644 --- a/examples/simple-auth/go.mod +++ b/examples/simple-auth/go.mod @@ -3,7 +3,7 @@ module simpleauth go 1.23.0 require ( - github.com/maddalax/htmgo/framework v1.0.3-0.20241109183230-b234ead96499 + github.com/maddalax/htmgo/framework v1.0.3-0.20241116145200-825c4dd7ecca github.com/mattn/go-sqlite3 v1.14.24 golang.org/x/crypto v0.28.0 ) diff --git a/examples/simple-auth/go.sum b/examples/simple-auth/go.sum index 37608bd..63c79e5 100644 --- a/examples/simple-auth/go.sum +++ b/examples/simple-auth/go.sum @@ -4,8 +4,8 @@ github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw= github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/maddalax/htmgo/framework v1.0.3-0.20241109183230-b234ead96499 h1:hQF++Rt9lJHUFk8PG097MTbpl2NnEcbot0iy8ZVPSOI= -github.com/maddalax/htmgo/framework v1.0.3-0.20241109183230-b234ead96499/go.mod h1:NGGzWVXWksrQJ9kV9SGa/A1F1Bjsgc08cN7ZVb98RqY= +github.com/maddalax/htmgo/framework v1.0.3-0.20241116145200-825c4dd7ecca h1:XiXldwjy1R6dqh7nr6X0coCu5OyA4WZsXVkayM4f4Tw= +github.com/maddalax/htmgo/framework v1.0.3-0.20241116145200-825c4dd7ecca/go.mod h1:NGGzWVXWksrQJ9kV9SGa/A1F1Bjsgc08cN7ZVb98RqY= github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBWDRM= github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/examples/todo-list/go.mod b/examples/todo-list/go.mod index 55a6def..38b2080 100644 --- a/examples/todo-list/go.mod +++ b/examples/todo-list/go.mod @@ -5,7 +5,7 @@ go 1.23.0 require ( entgo.io/ent v0.14.1 github.com/google/uuid v1.6.0 - github.com/maddalax/htmgo/framework v1.0.3-0.20241109183230-b234ead96499 + github.com/maddalax/htmgo/framework v1.0.3-0.20241116145200-825c4dd7ecca github.com/mattn/go-sqlite3 v1.14.23 ) diff --git a/examples/todo-list/go.sum b/examples/todo-list/go.sum index beaf601..09f077a 100644 --- a/examples/todo-list/go.sum +++ b/examples/todo-list/go.sum @@ -33,8 +33,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= -github.com/maddalax/htmgo/framework v1.0.3-0.20241109183230-b234ead96499 h1:hQF++Rt9lJHUFk8PG097MTbpl2NnEcbot0iy8ZVPSOI= -github.com/maddalax/htmgo/framework v1.0.3-0.20241109183230-b234ead96499/go.mod h1:NGGzWVXWksrQJ9kV9SGa/A1F1Bjsgc08cN7ZVb98RqY= +github.com/maddalax/htmgo/framework v1.0.3-0.20241116145200-825c4dd7ecca h1:XiXldwjy1R6dqh7nr6X0coCu5OyA4WZsXVkayM4f4Tw= +github.com/maddalax/htmgo/framework v1.0.3-0.20241116145200-825c4dd7ecca/go.mod h1:NGGzWVXWksrQJ9kV9SGa/A1F1Bjsgc08cN7ZVb98RqY= github.com/mattn/go-sqlite3 v1.14.23 h1:gbShiuAP1W5j9UOksQ06aiiqPMxYecovVGwmTxWtuw0= github.com/mattn/go-sqlite3 v1.14.23/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM= diff --git a/examples/ws-example/go.mod b/examples/ws-example/go.mod index d9323ee..91af23a 100644 --- a/examples/ws-example/go.mod +++ b/examples/ws-example/go.mod @@ -4,7 +4,7 @@ go 1.23.0 require ( github.com/maddalax/htmgo/extensions/websocket v0.0.0-20241109180553-34e816ff7c8a - github.com/maddalax/htmgo/framework v1.0.3-0.20241109183230-b234ead96499 + github.com/maddalax/htmgo/framework v1.0.3-0.20241116145200-825c4dd7ecca ) require ( diff --git a/examples/ws-example/go.sum b/examples/ws-example/go.sum index 0eff937..ac51c0e 100644 --- a/examples/ws-example/go.sum +++ b/examples/ws-example/go.sum @@ -12,8 +12,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/maddalax/htmgo/extensions/websocket v0.0.0-20241109180553-34e816ff7c8a h1:BYVo9NCLHgXvf5pCGUnVg8UE7d9mWOyLgWXYTgVTkyA= github.com/maddalax/htmgo/extensions/websocket v0.0.0-20241109180553-34e816ff7c8a/go.mod h1:r6/VqntLp7VlAUpIXy3MWZMHs2EkPKJP5rJdDL8lFP4= -github.com/maddalax/htmgo/framework v1.0.3-0.20241109183230-b234ead96499 h1:hQF++Rt9lJHUFk8PG097MTbpl2NnEcbot0iy8ZVPSOI= -github.com/maddalax/htmgo/framework v1.0.3-0.20241109183230-b234ead96499/go.mod h1:NGGzWVXWksrQJ9kV9SGa/A1F1Bjsgc08cN7ZVb98RqY= +github.com/maddalax/htmgo/framework v1.0.3-0.20241116145200-825c4dd7ecca h1:XiXldwjy1R6dqh7nr6X0coCu5OyA4WZsXVkayM4f4Tw= +github.com/maddalax/htmgo/framework v1.0.3-0.20241116145200-825c4dd7ecca/go.mod h1:NGGzWVXWksrQJ9kV9SGa/A1F1Bjsgc08cN7ZVb98RqY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/puzpuzpuz/xsync/v3 v3.4.0 h1:DuVBAdXuGFHv8adVXjWWZ63pJq+NRXOWVXlKDBZ+mJ4= diff --git a/extensions/websocket/go.mod b/extensions/websocket/go.mod index 079fc63..ac40d1f 100644 --- a/extensions/websocket/go.mod +++ b/extensions/websocket/go.mod @@ -4,7 +4,7 @@ go 1.23.0 require ( github.com/gobwas/ws v1.4.0 - github.com/maddalax/htmgo/framework v1.0.3-0.20241109183230-b234ead96499 + github.com/maddalax/htmgo/framework v1.0.3-0.20241116145200-825c4dd7ecca github.com/puzpuzpuz/xsync/v3 v3.4.0 github.com/stretchr/testify v1.9.0 ) diff --git a/extensions/websocket/go.sum b/extensions/websocket/go.sum index 33991dc..3b99e07 100644 --- a/extensions/websocket/go.sum +++ b/extensions/websocket/go.sum @@ -10,8 +10,8 @@ github.com/gobwas/ws v1.4.0 h1:CTaoG1tojrh4ucGPcoJFiAQUAsEWekEWvLy7GsVNqGs= github.com/gobwas/ws v1.4.0/go.mod h1:G3gNqMNtPppf5XUz7O4shetPpcZ1VJ7zt18dlUeakrc= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/maddalax/htmgo/framework v1.0.3-0.20241109183230-b234ead96499 h1:hQF++Rt9lJHUFk8PG097MTbpl2NnEcbot0iy8ZVPSOI= -github.com/maddalax/htmgo/framework v1.0.3-0.20241109183230-b234ead96499/go.mod h1:NGGzWVXWksrQJ9kV9SGa/A1F1Bjsgc08cN7ZVb98RqY= +github.com/maddalax/htmgo/framework v1.0.3-0.20241116145200-825c4dd7ecca h1:XiXldwjy1R6dqh7nr6X0coCu5OyA4WZsXVkayM4f4Tw= +github.com/maddalax/htmgo/framework v1.0.3-0.20241116145200-825c4dd7ecca/go.mod h1:NGGzWVXWksrQJ9kV9SGa/A1F1Bjsgc08cN7ZVb98RqY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/puzpuzpuz/xsync/v3 v3.4.0 h1:DuVBAdXuGFHv8adVXjWWZ63pJq+NRXOWVXlKDBZ+mJ4= diff --git a/extensions/websocket/init.go b/extensions/websocket/init.go index 980691e..9261063 100644 --- a/extensions/websocket/init.go +++ b/extensions/websocket/init.go @@ -21,8 +21,8 @@ func EnableExtension(app *h.App, opts opts.ExtensionOpts) { panic("websocket: SessionId func is required") } - service.Set[ws.SocketManager](app.Opts.ServiceLocator, service.Singleton, func() *ws.SocketManager { - manager := ws.NewSocketManager(&opts) + service.Set[wsutil.SocketManager](app.Opts.ServiceLocator, service.Singleton, func() *wsutil.SocketManager { + manager := wsutil.NewSocketManager(&opts) manager.StartMetrics() return manager }) diff --git a/extensions/websocket/internal/wsutil/handler.go b/extensions/websocket/internal/wsutil/handler.go index 0b320b9..1096dd5 100644 --- a/extensions/websocket/internal/wsutil/handler.go +++ b/extensions/websocket/internal/wsutil/handler.go @@ -6,7 +6,6 @@ import ( "github.com/gobwas/ws" "github.com/gobwas/ws/wsutil" ws2 "github.com/maddalax/htmgo/extensions/websocket/opts" - ws3 "github.com/maddalax/htmgo/extensions/websocket/ws" "github.com/maddalax/htmgo/framework/h" "github.com/maddalax/htmgo/framework/service" "log/slog" @@ -26,7 +25,7 @@ func WsHttpHandler(opts *ws2.ExtensionOpts) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { cc := r.Context().Value(h.RequestContextKey).(*h.RequestContext) locator := cc.ServiceLocator() - manager := service.Get[ws3.SocketManager](locator) + manager := service.Get[SocketManager](locator) sessionId := opts.SessionId(cc) @@ -47,7 +46,7 @@ func WsHttpHandler(opts *ws2.ExtensionOpts) http.HandlerFunc { we don't want to block the writer */ done := make(chan bool, 1000) - writer := make(ws3.WriterChan, 1000) + writer := make(WriterChan, 1000) wg := sync.WaitGroup{} diff --git a/extensions/websocket/ws/manager.go b/extensions/websocket/internal/wsutil/manager.go similarity index 99% rename from extensions/websocket/ws/manager.go rename to extensions/websocket/internal/wsutil/manager.go index b250f7b..34988cd 100644 --- a/extensions/websocket/ws/manager.go +++ b/extensions/websocket/internal/wsutil/manager.go @@ -1,4 +1,4 @@ -package ws +package wsutil import ( "fmt" diff --git a/extensions/websocket/ws/manager_test.go b/extensions/websocket/internal/wsutil/manager_test.go similarity index 99% rename from extensions/websocket/ws/manager_test.go rename to extensions/websocket/internal/wsutil/manager_test.go index 3c05a6f..0ba95d4 100644 --- a/extensions/websocket/ws/manager_test.go +++ b/extensions/websocket/internal/wsutil/manager_test.go @@ -1,4 +1,4 @@ -package ws +package wsutil import ( ws2 "github.com/maddalax/htmgo/extensions/websocket/opts" diff --git a/extensions/websocket/ws/access.go b/extensions/websocket/ws/access.go index 012d859..efa63c5 100644 --- a/extensions/websocket/ws/access.go +++ b/extensions/websocket/ws/access.go @@ -1,9 +1,10 @@ package ws import ( + "github.com/maddalax/htmgo/extensions/websocket/internal/wsutil" "github.com/maddalax/htmgo/framework/h" ) -func ManagerFromCtx(ctx *h.RequestContext) *SocketManager { - return SocketManagerFromCtx(ctx) +func ManagerFromCtx(ctx *h.RequestContext) *wsutil.SocketManager { + return wsutil.SocketManagerFromCtx(ctx) } diff --git a/extensions/websocket/ws/dispatch.go b/extensions/websocket/ws/dispatch.go index 53ed0f3..248b649 100644 --- a/extensions/websocket/ws/dispatch.go +++ b/extensions/websocket/ws/dispatch.go @@ -1,6 +1,7 @@ package ws import ( + "github.com/maddalax/htmgo/extensions/websocket/internal/wsutil" "github.com/maddalax/htmgo/extensions/websocket/session" "github.com/maddalax/htmgo/framework/h" "github.com/maddalax/htmgo/framework/service" @@ -32,7 +33,7 @@ func PushElement(data HandlerData, el *h.Element) bool { // PushElementCtx sends an element to the current session and swaps it into the page func PushElementCtx(ctx *h.RequestContext, el *h.Element) bool { locator := ctx.ServiceLocator() - socketManager := service.Get[SocketManager](locator) + socketManager := service.Get[wsutil.SocketManager](locator) socketId := session.GetSessionId(ctx) socket := socketManager.Get(string(socketId)) if socket == nil { diff --git a/extensions/websocket/ws/every.go b/extensions/websocket/ws/every.go index d549c53..679d3d5 100644 --- a/extensions/websocket/ws/every.go +++ b/extensions/websocket/ws/every.go @@ -1,6 +1,7 @@ package ws import ( + "github.com/maddalax/htmgo/extensions/websocket/internal/wsutil" "github.com/maddalax/htmgo/extensions/websocket/session" "github.com/maddalax/htmgo/framework/h" "github.com/maddalax/htmgo/framework/service" @@ -11,7 +12,7 @@ import ( func Every(ctx *h.RequestContext, interval time.Duration, cb func() bool) { socketId := session.GetSessionId(ctx) locator := ctx.ServiceLocator() - manager := service.Get[SocketManager](locator) + manager := service.Get[wsutil.SocketManager](locator) manager.RunIntervalWithSocket(string(socketId), interval, cb) } diff --git a/extensions/websocket/ws/handler.go b/extensions/websocket/ws/handler.go index 07c3080..2d0bbb7 100644 --- a/extensions/websocket/ws/handler.go +++ b/extensions/websocket/ws/handler.go @@ -2,15 +2,16 @@ package ws import ( "fmt" + "github.com/maddalax/htmgo/extensions/websocket/internal/wsutil" "github.com/maddalax/htmgo/extensions/websocket/session" "sync" ) type MessageHandler struct { - manager *SocketManager + manager *wsutil.SocketManager } -func NewMessageHandler(manager *SocketManager) *MessageHandler { +func NewMessageHandler(manager *wsutil.SocketManager) *MessageHandler { return &MessageHandler{manager: manager} } @@ -76,7 +77,7 @@ func (h *MessageHandler) OnDomElementRemoved(handlerId string) { handlers.Delete(handlerId) } -func (h *MessageHandler) OnSocketDisconnected(event SocketEvent) { +func (h *MessageHandler) OnSocketDisconnected(event wsutil.SocketEvent) { sessionId := session.Id(event.SessionId) hashes, ok := sessionIdToHashes.Load(sessionId) if ok { diff --git a/extensions/websocket/ws/listener.go b/extensions/websocket/ws/listener.go index 9b4965b..5556331 100644 --- a/extensions/websocket/ws/listener.go +++ b/extensions/websocket/ws/listener.go @@ -1,12 +1,13 @@ package ws import ( + "github.com/maddalax/htmgo/extensions/websocket/internal/wsutil" "github.com/maddalax/htmgo/extensions/websocket/session" "github.com/maddalax/htmgo/framework/service" ) func StartListener(locator *service.Locator) { - manager := service.Get[SocketManager](locator) + manager := service.Get[wsutil.SocketManager](locator) manager.Listen(socketMessageListener) handler := NewMessageHandler(manager) go func() { @@ -22,9 +23,9 @@ func handle(handler *MessageHandler) { handler.OnServerSideEvent(event) case event := <-socketMessageListener: switch event.Type { - case DisconnectedEvent: + case wsutil.DisconnectedEvent: handler.OnSocketDisconnected(event) - case MessageEvent: + case wsutil.MessageEvent: handlerId, ok := event.Payload["id"].(string) eventName, ok2 := event.Payload["event"].(string) diff --git a/extensions/websocket/ws/metrics.go b/extensions/websocket/ws/metrics.go index 29bbe79..258493b 100644 --- a/extensions/websocket/ws/metrics.go +++ b/extensions/websocket/ws/metrics.go @@ -1,11 +1,12 @@ package ws import ( + "github.com/maddalax/htmgo/extensions/websocket/internal/wsutil" "github.com/maddalax/htmgo/framework/h" ) type Metrics struct { - Manager ManagerMetrics + Manager wsutil.ManagerMetrics Handler HandlerMetrics } diff --git a/extensions/websocket/ws/register.go b/extensions/websocket/ws/register.go index d24d0d1..b7350fd 100644 --- a/extensions/websocket/ws/register.go +++ b/extensions/websocket/ws/register.go @@ -1,6 +1,7 @@ package ws import ( + "github.com/maddalax/htmgo/extensions/websocket/internal/wsutil" "github.com/maddalax/htmgo/extensions/websocket/session" "github.com/maddalax/htmgo/framework/h" "github.com/puzpuzpuz/xsync/v3" @@ -10,8 +11,8 @@ import ( type HandlerData struct { SessionId session.Id - Socket *SocketConnection - Manager *SocketManager + Socket *wsutil.SocketConnection + Manager *wsutil.SocketManager } type Handler func(data HandlerData) @@ -28,7 +29,7 @@ var sessionIdToHashes = xsync.NewMapOf[session.Id, map[KeyHash]bool]() var hashesToSessionId = xsync.NewMapOf[KeyHash, session.Id]() var serverEventNamesToHash = xsync.NewMapOf[string, map[KeyHash]bool]() -var socketMessageListener = make(chan SocketEvent, 100) +var socketMessageListener = make(chan wsutil.SocketEvent, 100) var serverSideMessageListener = make(chan ServerSideEvent, 100) var lock = sync.Mutex{} var callingHandler = atomic.Bool{} diff --git a/framework-ui/go.mod b/framework-ui/go.mod index 48776cf..a25192c 100644 --- a/framework-ui/go.mod +++ b/framework-ui/go.mod @@ -2,7 +2,7 @@ module github.com/maddalax/htmgo/framework-ui go 1.23.0 -require github.com/maddalax/htmgo/framework v1.0.3-0.20241109183230-b234ead96499 +require github.com/maddalax/htmgo/framework v1.0.3-0.20241116145200-825c4dd7ecca require ( github.com/go-chi/chi/v5 v5.1.0 // indirect diff --git a/framework-ui/go.sum b/framework-ui/go.sum index b93d222..1468ba2 100644 --- a/framework-ui/go.sum +++ b/framework-ui/go.sum @@ -4,8 +4,8 @@ github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw= github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/maddalax/htmgo/framework v1.0.3-0.20241109183230-b234ead96499 h1:hQF++Rt9lJHUFk8PG097MTbpl2NnEcbot0iy8ZVPSOI= -github.com/maddalax/htmgo/framework v1.0.3-0.20241109183230-b234ead96499/go.mod h1:NGGzWVXWksrQJ9kV9SGa/A1F1Bjsgc08cN7ZVb98RqY= +github.com/maddalax/htmgo/framework v1.0.3-0.20241116145200-825c4dd7ecca h1:XiXldwjy1R6dqh7nr6X0coCu5OyA4WZsXVkayM4f4Tw= +github.com/maddalax/htmgo/framework v1.0.3-0.20241116145200-825c4dd7ecca/go.mod h1:NGGzWVXWksrQJ9kV9SGa/A1F1Bjsgc08cN7ZVb98RqY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= diff --git a/framework/h/command_test.go b/framework/h/command_test.go index 2442506..ff331eb 100644 --- a/framework/h/command_test.go +++ b/framework/h/command_test.go @@ -7,6 +7,7 @@ import ( "regexp" "strings" "testing" + "time" ) func findScriptById(n *html.Node, id string) *html.Node { @@ -87,7 +88,7 @@ func TestJsEval(t *testing.T) { } func TestSetText(t *testing.T) { - compareIgnoreSpaces(t, renderJs(t, SetText("Hello World")), "this.innerText = 'Hello World';") + compareIgnoreSpaces(t, renderJs(t, SetText("Hello World")), "(self||this).innerText = 'Hello World';") } func TestSetTextOnChildren(t *testing.T) { @@ -100,42 +101,42 @@ func TestSetTextOnChildren(t *testing.T) { } func TestIncrement(t *testing.T) { - compareIgnoreSpaces(t, renderJs(t, Increment(5)), "this.innerText = parseInt(this.innerText) + 5;") + compareIgnoreSpaces(t, renderJs(t, Increment(5)), "(self||this).innerText = parseInt((self||this).innerText) + 5;") } func TestSetInnerHtml(t *testing.T) { htmlContent := Div(Span(UnsafeRaw("inner content"))) - compareIgnoreSpaces(t, renderJs(t, SetInnerHtml(htmlContent)), "this.innerHTML = `