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.
a52df99
— Peter John
2022-03-20T18:55:48+05:30
remove aws
Generated files not shown: go.sum
- cmd/gromer/main.go +4 -12
- example/main.go +4 -14
- go.mod +1 -1
- http.go +1 -3
cmd/gromer/main.go
CHANGED
|
@@ -223,7 +223,6 @@ import (
|
|
|
223
223
|
"net/http"
|
|
224
224
|
"os"
|
|
225
225
|
|
|
226
|
-
"github.com/apex/gateway/v2"
|
|
227
226
|
"github.com/gorilla/mux"
|
|
228
227
|
"github.com/pyros2097/gromer"
|
|
229
228
|
"github.com/rs/zerolog/log"
|
|
@@ -245,17 +244,10 @@ func main() {
|
|
|
245
244
|
handle(r, "GET", "/api", gromer.ApiExplorer(apiDefinitions()))
|
|
246
245
|
{{#each routes as |route| }}handle(r, "{{ route.Method }}", "{{ route.Path }}", {{ route.Pkg }}.{{ route.Method }})
|
|
247
246
|
{{/each}}
|
|
248
|
-
if !gromer.IsLambda {
|
|
249
|
-
|
|
247
|
+
println("http server listening on http://localhost:"+port)
|
|
250
|
-
|
|
248
|
+
srv := server.New(r, nil)
|
|
251
|
-
|
|
249
|
+
if err := srv.ListenAndServe(":"+port); err != nil {
|
|
252
|
-
|
|
250
|
+
log.Fatal().Stack().Err(err).Msg("failed to listen")
|
|
253
|
-
}
|
|
254
|
-
} else {
|
|
255
|
-
log.Print("running in lambda mode")
|
|
256
|
-
if err := gateway.ListenAndServe(":"+port, r); err != nil {
|
|
257
|
-
log.Fatal().Stack().Err(err).Msg("failed to listen")
|
|
258
|
-
}
|
|
259
251
|
}
|
|
260
252
|
}
|
|
261
253
|
|
example/main.go
CHANGED
|
@@ -7,7 +7,6 @@ import (
|
|
|
7
7
|
"net/http"
|
|
8
8
|
"os"
|
|
9
9
|
|
|
10
|
-
"github.com/apex/gateway/v2"
|
|
11
10
|
"github.com/gorilla/mux"
|
|
12
11
|
"github.com/pyros2097/gromer"
|
|
13
12
|
"github.com/rs/zerolog/log"
|
|
@@ -25,7 +24,6 @@ import (
|
|
|
25
24
|
var assetsFS embed.FS
|
|
26
25
|
|
|
27
26
|
func main() {
|
|
28
|
-
isLambda := os.Getenv("_LAMBDA_SERVER_PORT") != ""
|
|
29
27
|
r := mux.NewRouter()
|
|
30
28
|
r.Use(gromer.LogMiddleware)
|
|
31
29
|
r.NotFoundHandler = gromer.NotFoundHandler
|
|
@@ -39,18 +37,10 @@ func main() {
|
|
|
39
37
|
handle(r, "POST", "/api/todos", todos.POST)
|
|
40
38
|
handle(r, "GET", "/api/recover", recover.GET)
|
|
41
39
|
handle(r, "GET", "/", pages.GET)
|
|
42
|
-
|
|
43
|
-
if !isLambda {
|
|
44
|
-
|
|
40
|
+
println("http server listening on http://localhost:3000")
|
|
45
|
-
|
|
41
|
+
srv := server.New(r, nil)
|
|
46
|
-
|
|
42
|
+
if err := srv.ListenAndServe(":3000"); err != nil {
|
|
47
|
-
|
|
43
|
+
log.Fatal().Stack().Err(err).Msg("failed to listen")
|
|
48
|
-
}
|
|
49
|
-
} else {
|
|
50
|
-
log.Print("running in lambda mode")
|
|
51
|
-
if err := gateway.ListenAndServe(":3000", r); err != nil {
|
|
52
|
-
log.Fatal().Stack().Err(err).Msg("failed to listen")
|
|
53
|
-
}
|
|
54
44
|
}
|
|
55
45
|
}
|
|
56
46
|
|
go.mod
CHANGED
|
@@ -3,7 +3,6 @@ module github.com/pyros2097/gromer
|
|
|
3
3
|
go 1.16
|
|
4
4
|
|
|
5
5
|
require (
|
|
6
|
-
github.com/apex/gateway/v2 v2.0.0
|
|
7
6
|
github.com/aymerick/raymond v2.0.2+incompatible // indirect
|
|
8
7
|
github.com/bradleyjkemp/cupaloy v2.3.0+incompatible
|
|
9
8
|
github.com/franela/goblin v0.0.0-20211003143422-0a4f594942bf
|
|
@@ -24,6 +23,7 @@ require (
|
|
|
24
23
|
github.com/shurcooL/highlight_diff v0.0.0-20181222201841-111da2e7d480 // indirect
|
|
25
24
|
github.com/shurcooL/highlight_go v0.0.0-20191220051317-782971ddf21b // indirect
|
|
26
25
|
github.com/shurcooL/octicon v0.0.0-20191102190552-cbb32d6a785c // indirect
|
|
26
|
+
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
|
|
27
27
|
github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d // indirect
|
|
28
28
|
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e // indirect
|
|
29
29
|
github.com/stretchr/testify v1.7.0
|
http.go
CHANGED
|
@@ -21,15 +21,13 @@ import (
|
|
|
21
21
|
)
|
|
22
22
|
|
|
23
23
|
var info *debug.BuildInfo
|
|
24
|
-
var IsLambda bool
|
|
25
24
|
var IsCloundRun bool
|
|
26
25
|
|
|
27
26
|
func init() {
|
|
28
|
-
IsLambda = os.Getenv("_LAMBDA_SERVER_PORT") != ""
|
|
29
27
|
IsCloundRun = os.Getenv("K_REVISION") != ""
|
|
30
28
|
info, _ = debug.ReadBuildInfo()
|
|
31
29
|
zerolog.ErrorStackMarshaler = pkgerrors.MarshalStack
|
|
32
|
-
if !
|
|
30
|
+
if !IsCloundRun {
|
|
33
31
|
log.Logger = log.Output(zerolog.ConsoleWriter{
|
|
34
32
|
Out: os.Stdout,
|
|
35
33
|
TimeFormat: zerolog.TimeFormatUnix,
|