~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.
fix validation errors
_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
|
)
|
go.sum
CHANGED
|
@@ -146,6 +146,8 @@ github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnht
|
|
|
146
146
|
github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
|
147
147
|
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
|
148
148
|
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
|
149
|
+
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 h1:y5HC9v93H5EPKqaS1UYVg1uYah5Xf51mBfIoWehClUQ=
|
|
150
|
+
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964/go.mod h1:Xd9hchkHSWYkEqJwUGisez3G1QY8Ryz0sdWrLPMGjLk=
|
|
149
151
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
150
152
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
|
151
153
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
@@ -186,6 +188,8 @@ github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GO
|
|
|
186
188
|
github.com/go-playground/validator/v10 v10.9.0 h1:NgTtmN58D0m8+UuxtYmGztBJB7VnPgjj221I1QHci2A=
|
|
187
189
|
github.com/go-playground/validator/v10 v10.9.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos=
|
|
188
190
|
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
|
191
|
+
github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw=
|
|
192
|
+
github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4=
|
|
189
193
|
github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo=
|
|
190
194
|
github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
|
|
191
195
|
github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM=
|
|
@@ -288,7 +292,9 @@ github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv
|
|
|
288
292
|
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
|
|
289
293
|
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
|
290
294
|
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
|
295
|
+
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
|
291
296
|
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
|
|
297
|
+
github.com/h2non/filetype v1.1.1/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY=
|
|
292
298
|
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
|
293
299
|
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
|
294
300
|
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
|
|
@@ -330,6 +336,8 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN
|
|
|
330
336
|
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
|
331
337
|
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
|
332
338
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
|
339
|
+
github.com/playwright-community/playwright-go v0.2000.1 h1:2JViSHpJQ/UL/PO1Gg6gXV5IcXAAsoBJ3KG9L3wKXto=
|
|
340
|
+
github.com/playwright-community/playwright-go v0.2000.1/go.mod h1:1y9cM9b9dVHnuRWzED1KLM7FtbwTJC8ibDjI6MNqewU=
|
|
333
341
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
|
334
342
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
|
335
343
|
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
|
@@ -786,6 +794,8 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8
|
|
|
786
794
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
|
787
795
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
|
788
796
|
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
|
797
|
+
gopkg.in/square/go-jose.v2 v2.6.0 h1:NGk74WTnPKBNUhNzQX7PYcTLUjoq7mzKk2OKbvwk2iI=
|
|
798
|
+
gopkg.in/square/go-jose.v2 v2.6.0/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
|
|
789
799
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
790
800
|
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
791
801
|
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
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 {
|