gromer
git clone https://git.pyrossh.dev/gromer
gromer is a framework and cli to build multipage web apps in golang using htmx and alpinejs.
1a2b945
— pyros2097
2020-12-09T07:10:54+05:30
improve api
Generated files not shown: go.sum
- app_nowasm.go +12 -12
- app_wasm.go +1 -1
- example/main.go +3 -3
- example/makefile +7 -4
- go.mod +2 -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/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
|