-
Notifications
You must be signed in to change notification settings - Fork 8
/
json_context.go
68 lines (53 loc) · 1.55 KB
/
json_context.go
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package transformers
import (
"github.com/tidwall/gjson"
"github.com/greenmaskio/greenmask/internal/db/postgres/transformers/utils/template"
"github.com/greenmaskio/greenmask/pkg/toolkit"
)
type JsonContext struct {
exists bool
originalValue any
path string
rc *template.RecordContext
}
func NewJsonContext() *JsonContext {
return &JsonContext{
rc: &template.RecordContext{},
}
}
func (jc *JsonContext) setValue(data []byte, path string) {
res := gjson.GetBytes(data, path)
jc.originalValue = res.Value()
jc.exists = res.Exists()
jc.path = path
}
func (jc *JsonContext) setRecord(r *toolkit.Record) {
jc.rc.SetRecord(r)
}
func (jc *JsonContext) GetPath() string {
return jc.path
}
func (jc *JsonContext) GetOriginalValue() any {
return jc.originalValue
}
func (jc *JsonContext) OriginalValueExists() bool {
return jc.exists
}
func (jc *JsonContext) GetColumnValue(name string) (any, error) {
return jc.rc.GetColumnValue(name)
}
func (jc *JsonContext) GetColumnRawValue(name string) (any, error) {
return jc.rc.GetRawColumnValue(name)
}
func (jc *JsonContext) EncodeValueByColumn(name string, v any) (any, error) {
return jc.rc.EncodeValueByColumn(name, v)
}
func (jc *JsonContext) DecodeValueByColumn(name string, v any) (any, error) {
return jc.rc.DecodeValueByColumn(name, v)
}
func (jc *JsonContext) EncodeValueByType(name string, v any) (any, error) {
return jc.rc.EncodeValueByType(name, v)
}
func (jc *JsonContext) DecodeValueByType(name string, v any) (any, error) {
return jc.rc.DecodeValueByType(name, v)
}