~repos /gromer
git clone https://pyrossh.dev/repos/gromer.git
gromer is a framework and cli to build multipage web apps in golang using htmx and alpinejs.
9ed191f8
—
pyros2097 5 years ago
improve api
- app_nowasm.go +12 -12
- app_wasm.go +1 -1
- example/example +0 -0
- example/main.go +3 -3
- example/makefile +7 -4
- go.mod +2 -0
- go.sum +6 -0
app_nowasm.go
CHANGED
|
@@ -9,39 +9,39 @@ import (
|
|
|
9
9
|
"os"
|
|
10
10
|
"path/filepath"
|
|
11
11
|
"strconv"
|
|
12
|
-
"strings"
|
|
13
12
|
|
|
14
13
|
"github.com/akrylysov/algnhsa"
|
|
15
14
|
"github.com/markbates/pkger"
|
|
15
|
+
"github.com/shurcooL/httpgzip"
|
|
16
16
|
)
|
|
17
17
|
|
|
18
|
-
func Run(
|
|
18
|
+
func Run(routes map[string]RenderFunc) {
|
|
19
19
|
wd, err := os.Getwd()
|
|
20
20
|
if err != nil {
|
|
21
21
|
fmt.Printf("could not get wd")
|
|
22
22
|
return
|
|
23
23
|
}
|
|
24
|
+
http.Handle("/assets/", http.StripPrefix("/assets", httpgzip.FileServer(
|
|
24
|
-
|
|
25
|
+
pkger.Dir(filepath.Join(wd, "assets")),
|
|
26
|
+
httpgzip.FileServerOptions{},
|
|
27
|
+
)))
|
|
25
28
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
26
29
|
println("route: " + r.URL.Path)
|
|
27
30
|
renderFunc := MatchRoute(routes, r.URL.Path)
|
|
28
|
-
if strings.Contains(r.URL.Path, "/assets") {
|
|
29
|
-
r.URL.Path = strings.Replace(r.URL.Path, "/assets", "", 1)
|
|
30
|
-
assetsFileServer.ServeHTTP(w, r)
|
|
31
|
-
return
|
|
32
|
-
}
|
|
33
31
|
page := createPage("wapp-example", renderFunc(NewRenderContext()))
|
|
34
32
|
w.Header().Set("Content-Length", strconv.Itoa(page.Len()))
|
|
35
33
|
w.Header().Set("Content-Type", "text/html")
|
|
36
34
|
w.WriteHeader(http.StatusOK)
|
|
37
35
|
w.Write(page.Bytes())
|
|
38
36
|
})
|
|
37
|
+
if os.Getenv("_LAMBDA_SERVER_PORT") != "" {
|
|
38
|
+
println("running in lambda mode")
|
|
39
|
+
algnhsa.ListenAndServe(http.DefaultServeMux, &algnhsa.Options{
|
|
40
|
+
BinaryContentTypes: []string{"application/wasm", "image/png"},
|
|
41
|
+
})
|
|
39
|
-
|
|
42
|
+
} else {
|
|
40
43
|
println("Serving on HTTP port: 1234")
|
|
41
44
|
http.ListenAndServe(":1234", nil)
|
|
42
|
-
} else {
|
|
43
|
-
println("algnhsa serving default mux")
|
|
44
|
-
algnhsa.ListenAndServe(http.DefaultServeMux, nil)
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
app_wasm.go
CHANGED
|
@@ -11,7 +11,7 @@ var (
|
|
|
11
11
|
rootPrefix string
|
|
12
12
|
)
|
|
13
13
|
|
|
14
|
-
func Run(
|
|
14
|
+
func Run(routes map[string]RenderFunc) {
|
|
15
15
|
renderFunc := MatchRoute(routes, js.Window.URL().Path)
|
|
16
16
|
defer func() {
|
|
17
17
|
err := recover()
|
example/example
ADDED
|
Binary file
|
example/main.go
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
package main
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
-
|
|
4
|
+
. "github.com/pyros2097/wapp"
|
|
5
5
|
)
|
|
6
6
|
|
|
7
|
-
var routes = map[string]
|
|
7
|
+
var routes = map[string]RenderFunc{
|
|
8
8
|
"/about": About,
|
|
9
9
|
"/clock": Clock,
|
|
10
10
|
"/container": Container,
|
|
@@ -12,5 +12,5 @@ var routes = map[string]app.RenderFunc{
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
func main() {
|
|
15
|
-
|
|
15
|
+
Run(routes)
|
|
16
16
|
}
|
example/makefile
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
run:
|
|
2
2
|
go run *.go
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
go:
|
|
5
5
|
go build
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
wasm:
|
|
8
8
|
GOOS=js GOARCH=wasm go build -o assets/main.wasm
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
css:
|
|
11
|
-
npx tailwindcss-cli@latest build assets/config.css -o assets/styles.css
|
|
11
|
+
npx tailwindcss-cli@latest build assets/config.css -o assets/styles.css
|
|
12
|
+
|
|
13
|
+
lambda:
|
|
14
|
+
sam local start-api
|
go.mod
CHANGED
|
@@ -6,7 +6,9 @@ require (
|
|
|
6
6
|
github.com/akrylysov/algnhsa v0.12.1
|
|
7
7
|
github.com/aws/aws-lambda-go v1.20.0
|
|
8
8
|
github.com/awslabs/goformation/v4 v4.15.6
|
|
9
|
+
github.com/kevinpollet/nego v0.0.0-20200702060216-3ff8e9f14a70
|
|
9
10
|
github.com/markbates/pkger v0.17.1
|
|
11
|
+
github.com/shurcooL/httpgzip v0.0.0-20190720172056-320755c1c1b0
|
|
10
12
|
github.com/stretchr/testify v1.6.1
|
|
11
13
|
golang.org/x/sys v0.0.0-20201112073958-5cba982894dd // indirect
|
|
12
14
|
gopkg.in/fsnotify.v1 v1.4.7
|
go.sum
CHANGED
|
@@ -30,6 +30,8 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
|
|
|
30
30
|
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
|
31
31
|
github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA=
|
|
32
32
|
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
|
|
33
|
+
github.com/kevinpollet/nego v0.0.0-20200702060216-3ff8e9f14a70 h1:vl63cy3DUIN3iZI5oU/2yfVXEFVPc5ahbwjWk0aF3nA=
|
|
34
|
+
github.com/kevinpollet/nego v0.0.0-20200702060216-3ff8e9f14a70/go.mod h1:bST7PtmFt4otZfrYPAUmYA1v3hZBhX4ttQzBSxeRE4E=
|
|
33
35
|
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
|
34
36
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
|
35
37
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
|
@@ -51,6 +53,8 @@ github.com/sanathkr/go-yaml v0.0.0-20170819195128-ed9d249f429b h1:jUK33OXuZP/l6b
|
|
|
51
53
|
github.com/sanathkr/go-yaml v0.0.0-20170819195128-ed9d249f429b/go.mod h1:8458kAagoME2+LN5//WxE71ysZ3B7r22fdgb7qVmXSY=
|
|
52
54
|
github.com/sanathkr/yaml v0.0.0-20170819201035-0056894fa522 h1:fOCp11H0yuyAt2wqlbJtbyPzSgaxHTv8uN1pMpkG1t8=
|
|
53
55
|
github.com/sanathkr/yaml v0.0.0-20170819201035-0056894fa522/go.mod h1:tQTYKOQgxoH3v6dEmdHiz4JG+nbxWwM5fgPQUpSZqVQ=
|
|
56
|
+
github.com/shurcooL/httpgzip v0.0.0-20190720172056-320755c1c1b0 h1:mj/nMDAwTBiaCqMEs4cYCqF7pO6Np7vhy1D1wcQGz+E=
|
|
57
|
+
github.com/shurcooL/httpgzip v0.0.0-20190720172056-320755c1c1b0/go.mod h1:919LwcH0M7/W4fcZ0/jy0qGght1GIhqyS/EgWGH2j5Q=
|
|
54
58
|
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
|
55
59
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
|
56
60
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
|
@@ -66,6 +70,7 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
|
|
|
66
70
|
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
|
67
71
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
|
68
72
|
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
|
73
|
+
golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0 h1:wBouT66WTYFXdxfVdz9sVWARVd/2vfGcmI45D2gj45M=
|
|
69
74
|
golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
|
70
75
|
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
71
76
|
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
@@ -81,6 +86,7 @@ golang.org/x/sys v0.0.0-20201112073958-5cba982894dd h1:5CtCZbICpIOFdgO940moixOPj
|
|
|
81
86
|
golang.org/x/sys v0.0.0-20201112073958-5cba982894dd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
82
87
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
|
83
88
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
|
89
|
+
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
|
|
84
90
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
85
91
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
|
86
92
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|