-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsonpath_collector.go
More file actions
25 lines (17 loc) · 861 Bytes
/
jsonpath_collector.go
File metadata and controls
25 lines (17 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package htmljson
// JSONPathCollector provides HTML renderers as its methods
// and collects which JSON path keys have been passed to it and which values.
// This is useful for testing.
type JSONPathCollector struct {
Keys map[string]any
}
func NewJSONPathCollector() *JSONPathCollector { return &JSONPathCollector{Keys: map[string]any{}} }
func (c *JSONPathCollector) add(k string, v any) string {
c.Keys[k] = v
return ""
}
func (c *JSONPathCollector) Null(k string) string { return c.add(k, "null") }
func (c *JSONPathCollector) Bool(k string, v bool) string { return c.add(k, v) }
func (c *JSONPathCollector) String(k string, v string) string { return c.add(k, v) }
func (c *JSONPathCollector) Number(k string, v float64, s string) string { return c.add(k, s) }
func (c *JSONPathCollector) MapKey(k string, v string) string { return c.add(k, v) }