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.
5fe2b50
— Peter John
2022-08-05T09:01:21+05:30
fix validation errors
Generated files not shown: go.sum
- _example/makefile +3 -0
- go.mod +4 -0
- http.go +11 -0
_example/makefile
CHANGED
|
@@ -5,6 +5,9 @@ setup:
|
|
|
5
5
|
dev:
|
|
6
6
|
gow run main.go
|
|
7
7
|
|
|
8
|
+
test:
|
|
9
|
+
go test -v ./...
|
|
10
|
+
|
|
8
11
|
build:
|
|
9
12
|
podman build -f ../_example/Containerfile -t example-app:develop ../
|
|
10
13
|
|
go.mod
CHANGED
|
@@ -25,15 +25,18 @@ require (
|
|
|
25
25
|
cloud.google.com/go v0.94.0 // indirect
|
|
26
26
|
cloud.google.com/go/firestore v1.5.0 // indirect
|
|
27
27
|
github.com/blang/semver v3.5.1+incompatible // indirect
|
|
28
|
+
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 // indirect
|
|
28
29
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
|
29
30
|
github.com/go-playground/locales v0.14.0 // indirect
|
|
30
31
|
github.com/go-playground/universal-translator v0.18.0 // indirect
|
|
32
|
+
github.com/go-stack/stack v1.8.1 // indirect
|
|
31
33
|
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
|
32
34
|
github.com/golang/protobuf v1.5.2 // indirect
|
|
33
35
|
github.com/google/go-cmp v0.5.6 // indirect
|
|
34
36
|
github.com/google/wire v0.5.0 // indirect
|
|
35
37
|
github.com/googleapis/gax-go/v2 v2.1.0 // indirect
|
|
36
38
|
github.com/leodido/go-urn v1.2.1 // indirect
|
|
39
|
+
github.com/playwright-community/playwright-go v0.2000.1 // indirect
|
|
37
40
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
|
38
41
|
go.opencensus.io v0.23.0 // indirect
|
|
39
42
|
golang.org/x/crypto v0.0.0-20211215165025-cf75a172585e // indirect
|
|
@@ -48,5 +51,6 @@ require (
|
|
|
48
51
|
google.golang.org/genproto v0.0.0-20210831024726-fe130286e0e2 // indirect
|
|
49
52
|
google.golang.org/grpc v1.40.0 // indirect
|
|
50
53
|
google.golang.org/protobuf v1.27.1 // indirect
|
|
54
|
+
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
|
|
51
55
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
|
52
56
|
)
|
http.go
CHANGED
|
@@ -20,6 +20,7 @@ import (
|
|
|
20
20
|
"time"
|
|
21
21
|
|
|
22
22
|
"github.com/felixge/httpsnoop"
|
|
23
|
+
"github.com/go-playground/validator/v10"
|
|
23
24
|
"github.com/google/uuid"
|
|
24
25
|
"github.com/gorilla/handlers"
|
|
25
26
|
"github.com/gorilla/mux"
|
|
@@ -71,6 +72,16 @@ func getFunctionName(temp interface{}) string {
|
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
func RespondError(w http.ResponseWriter, r *http.Request, status int, err error) {
|
|
75
|
+
validationErrors, ok := err.(validator.ValidationErrors)
|
|
76
|
+
if ok {
|
|
77
|
+
w.Header().Set("Content-Type", "application/json")
|
|
78
|
+
w.WriteHeader(status)
|
|
79
|
+
data, _ := json.Marshal(gsx.M{
|
|
80
|
+
"error": GetValidationError(validationErrors),
|
|
81
|
+
})
|
|
82
|
+
w.Write(data)
|
|
83
|
+
return
|
|
84
|
+
}
|
|
74
85
|
w.Header().Set("Content-Type", "text/html")
|
|
75
86
|
w.WriteHeader(status) // always write status last
|
|
76
87
|
if status >= 500 {
|