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.
0d137ca
— Peter John
2021-12-29T19:43:02+05:30
fix merge
Generated files not shown: go.sum
- go.mod +4 -4
- utils.go +21 -1
- utils_test.go +3 -2
go.mod
CHANGED
|
@@ -12,12 +12,12 @@ require (
|
|
|
12
12
|
github.com/google/uuid v1.3.0
|
|
13
13
|
github.com/gorilla/mux v1.8.0
|
|
14
14
|
github.com/iancoleman/strcase v0.2.0
|
|
15
|
-
github.com/imdario/mergo v0.3.12
|
|
15
|
+
github.com/imdario/mergo v0.3.12
|
|
16
16
|
github.com/lib/pq v1.10.4
|
|
17
17
|
github.com/markbates/inflect v1.0.4
|
|
18
|
-
github.com/microcosm-cc/bluemonday v1.0.
|
|
18
|
+
github.com/microcosm-cc/bluemonday v1.0.16 // indirect
|
|
19
19
|
github.com/pkg/errors v0.9.1
|
|
20
|
-
github.com/rs/zerolog v1.26.
|
|
20
|
+
github.com/rs/zerolog v1.26.1
|
|
21
21
|
github.com/sergi/go-diff v1.2.0 // indirect
|
|
22
22
|
github.com/shurcooL/github_flavored_markdown v0.0.0-20210228213109-c3a9aa474629
|
|
23
23
|
github.com/shurcooL/go v0.0.0-20200502201357-93f07166e636 // indirect
|
|
@@ -30,5 +30,5 @@ require (
|
|
|
30
30
|
github.com/stretchr/testify v1.7.0
|
|
31
31
|
gocloud.dev v0.24.0
|
|
32
32
|
golang.org/x/mod v0.5.1
|
|
33
|
-
golang.org/x/net v0.0.0-
|
|
33
|
+
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f
|
|
34
34
|
)
|
utils.go
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
package gromer
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
+
"reflect"
|
|
4
5
|
"regexp"
|
|
5
6
|
"strings"
|
|
7
|
+
"time"
|
|
6
8
|
|
|
7
9
|
"github.com/go-playground/validator/v10"
|
|
8
10
|
"github.com/iancoleman/strcase"
|
|
@@ -15,8 +17,26 @@ var ValidatorErrorMap = map[string]string{
|
|
|
15
17
|
}
|
|
16
18
|
var upperRegex = regexp.MustCompile("^[^a-z]*$")
|
|
17
19
|
|
|
20
|
+
type timeTransformer struct {
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
func (t timeTransformer) Transformer(typ reflect.Type) func(dst, src reflect.Value) error {
|
|
24
|
+
if typ == reflect.TypeOf(time.Time{}) {
|
|
25
|
+
return func(dst, src reflect.Value) error {
|
|
26
|
+
if dst.CanSet() {
|
|
27
|
+
srcResult := src.MethodByName("IsZero").Call([]reflect.Value{})
|
|
28
|
+
if !srcResult[0].Bool() {
|
|
29
|
+
dst.Set(src)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return nil
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return nil
|
|
36
|
+
}
|
|
37
|
+
|
|
18
38
|
func Merge(dst interface{}, src interface{}) error {
|
|
19
|
-
err := mergo.Merge(dst, src, mergo.
|
|
39
|
+
err := mergo.Merge(dst, src, mergo.WithOverride, mergo.WithTransformers(timeTransformer{}))
|
|
20
40
|
if err != nil {
|
|
21
41
|
return err
|
|
22
42
|
}
|
utils_test.go
CHANGED
|
@@ -91,6 +91,7 @@ func TestMerge(t *testing.T) {
|
|
|
91
91
|
Text: "2",
|
|
92
92
|
CreatedAt: time.Date(2020, 11, 11, 0, 0, 0, 0, time.UTC),
|
|
93
93
|
}, note)
|
|
94
|
+
// TODO: look at this merge
|
|
94
95
|
err = Merge(note, &Note{
|
|
95
96
|
ID: "2",
|
|
96
97
|
Text: "",
|
|
@@ -99,7 +100,7 @@ func TestMerge(t *testing.T) {
|
|
|
99
100
|
assert.NoError(t, err)
|
|
100
101
|
assert.EqualValues(t, &Note{
|
|
101
102
|
ID: "2",
|
|
102
|
-
Text: "",
|
|
103
|
+
Text: "2",
|
|
103
|
-
CreatedAt: time.
|
|
104
|
+
CreatedAt: time.Date(2020, 11, 11, 0, 0, 0, 0, time.UTC),
|
|
104
105
|
}, note)
|
|
105
106
|
}
|