~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.
bf39b374
—
Peter John 3 years ago
support timestamp in query param
- example/components/counter.go +16 -1
- http.go +12 -0
example/components/counter.go
CHANGED
|
@@ -7,6 +7,21 @@ import (
|
|
|
7
7
|
. "github.com/pyros2097/gromer"
|
|
8
8
|
)
|
|
9
9
|
|
|
10
|
+
type S map[string]interface{}
|
|
11
|
+
|
|
12
|
+
type CC func(nodes ...interface{}) *Element
|
|
13
|
+
|
|
14
|
+
func Styled2(s S) CC {
|
|
15
|
+
return func(nodes ...interface{}) *Element {
|
|
16
|
+
return Div(nodes...)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
var Container = Styled2(S{
|
|
21
|
+
"border-left": "2px",
|
|
22
|
+
"border-right": "2px",
|
|
23
|
+
})
|
|
24
|
+
|
|
10
25
|
func Counter(c context.Context, start int) *Element {
|
|
11
26
|
count, setCount := UseState(c, start)
|
|
12
27
|
increment := func() {
|
|
@@ -15,7 +30,7 @@ func Counter(c context.Context, start int) *Element {
|
|
|
15
30
|
decrement := func() {
|
|
16
31
|
setCount(count().(int) + 1)
|
|
17
32
|
}
|
|
18
|
-
return
|
|
33
|
+
return Container("123", Css("text-3xl text-gray-700"),
|
|
19
34
|
Row(
|
|
20
35
|
Row(Css("underline"),
|
|
21
36
|
Text("Counter"),
|
http.go
CHANGED
|
@@ -8,6 +8,7 @@ import (
|
|
|
8
8
|
"regexp"
|
|
9
9
|
"strconv"
|
|
10
10
|
"strings"
|
|
11
|
+
"time"
|
|
11
12
|
|
|
12
13
|
"github.com/fatih/color"
|
|
13
14
|
"github.com/go-playground/validator/v10"
|
|
@@ -106,6 +107,17 @@ func PerformRequest(route string, h interface{}, ctx interface{}, w http.Respons
|
|
|
106
107
|
}
|
|
107
108
|
f.SetInt(v)
|
|
108
109
|
}
|
|
110
|
+
} else if f.Kind() == reflect.Struct && f.Type().Name() == "Time" {
|
|
111
|
+
if jsonValue == "" {
|
|
112
|
+
f.Set(reflect.ValueOf(time.Time{}))
|
|
113
|
+
} else {
|
|
114
|
+
v, err := time.Parse(time.RFC3339, jsonValue)
|
|
115
|
+
if err != nil {
|
|
116
|
+
RespondError(w, 400, err)
|
|
117
|
+
return 400, err
|
|
118
|
+
}
|
|
119
|
+
f.Set(reflect.ValueOf(v))
|
|
120
|
+
}
|
|
109
121
|
} else {
|
|
110
122
|
panic("Uknown query param: " + jsonName + " " + jsonValue)
|
|
111
123
|
}
|