use yaml for parsing JSON - works without quotes on simple strings
This commit is contained in:
parent
9bb027ed4c
commit
00a6e70430
6 changed files with 29 additions and 28 deletions
|
@ -1,7 +1,8 @@
|
||||||
package rep
|
package rep
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
//"encoding/json"
|
||||||
|
json "gopkg.in/yaml.v3"
|
||||||
|
|
||||||
"git.sr.ht/~cco/go-scopes/logging/log"
|
"git.sr.ht/~cco/go-scopes/logging/log"
|
||||||
)
|
)
|
||||||
|
|
3
go.mod
3
go.mod
|
@ -6,8 +6,8 @@ require (
|
||||||
github.com/gin-gonic/gin v1.9.1
|
github.com/gin-gonic/gin v1.9.1
|
||||||
github.com/lib/pq v1.10.9
|
github.com/lib/pq v1.10.9
|
||||||
github.com/rs/zerolog v1.29.1
|
github.com/rs/zerolog v1.29.1
|
||||||
golang.org/x/exp v0.0.0-20230725093048-515e97ebf090
|
|
||||||
golang.org/x/net v0.10.0
|
golang.org/x/net v0.10.0
|
||||||
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
modernc.org/sqlite v1.25.0
|
modernc.org/sqlite v1.25.0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -41,7 +41,6 @@ require (
|
||||||
golang.org/x/text v0.9.0 // indirect
|
golang.org/x/text v0.9.0 // indirect
|
||||||
golang.org/x/tools v0.6.0 // indirect
|
golang.org/x/tools v0.6.0 // indirect
|
||||||
google.golang.org/protobuf v1.30.0 // indirect
|
google.golang.org/protobuf v1.30.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
|
||||||
lukechampine.com/uint128 v1.2.0 // indirect
|
lukechampine.com/uint128 v1.2.0 // indirect
|
||||||
modernc.org/cc/v3 v3.40.0 // indirect
|
modernc.org/cc/v3 v3.40.0 // indirect
|
||||||
modernc.org/ccgo/v3 v3.16.13 // indirect
|
modernc.org/ccgo/v3 v3.16.13 // indirect
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -90,8 +90,6 @@ golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k=
|
||||||
golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
||||||
golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=
|
golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=
|
||||||
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
|
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
|
||||||
golang.org/x/exp v0.0.0-20230725093048-515e97ebf090 h1:Di6/M8l0O2lCLc6VVRWhgCiApHV8MnQurBnFSHsQtNY=
|
|
||||||
golang.org/x/exp v0.0.0-20230725093048-515e97ebf090/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
|
|
||||||
golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU=
|
golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU=
|
||||||
golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||||
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
|
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
|
||||||
|
|
|
@ -61,13 +61,14 @@ func init() {
|
||||||
ixs := []lib.StrSlice{hf}
|
ixs := []lib.StrSlice{hf}
|
||||||
ixs = append(ixs, lib.StrSlice{"domain", "class", "item"})
|
ixs = append(ixs, lib.StrSlice{"domain", "class", "item"})
|
||||||
container_definition = &tracking.ContDef{
|
container_definition = &tracking.ContDef{
|
||||||
Prefix: type_prefix,
|
Prefix: type_prefix,
|
||||||
ContFactory: Messages,
|
ContFactory: Messages,
|
||||||
ItemFactory: MakeMessage,
|
ItemFactory: MakeMessage,
|
||||||
TableName: "messages",
|
TableName: "messages",
|
||||||
HeadFields: hf,
|
HeadFields: hf,
|
||||||
IdFields: hf,
|
IdFields: hf,
|
||||||
Indexes: ixs,
|
Indexes: ixs,
|
||||||
|
InsertOnChange: true,
|
||||||
}
|
}
|
||||||
tracking.RegisterContainerDef(container_definition)
|
tracking.RegisterContainerDef(container_definition)
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,13 +85,14 @@ func (tr *Track) ScanP(rows *sql.Rows) error {
|
||||||
// basic container implementation
|
// basic container implementation
|
||||||
|
|
||||||
type ContDef struct {
|
type ContDef struct {
|
||||||
Prefix string
|
Prefix string
|
||||||
ContFactory ContFactory
|
ContFactory ContFactory
|
||||||
ItemFactory ItemFactory
|
ItemFactory ItemFactory
|
||||||
TableName string
|
TableName string
|
||||||
HeadFields lib.StrSlice
|
HeadFields lib.StrSlice
|
||||||
IdFields lib.StrSlice
|
IdFields lib.StrSlice
|
||||||
Indexes []lib.StrSlice
|
Indexes []lib.StrSlice
|
||||||
|
InsertOnChange bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type Container struct {
|
type Container struct {
|
||||||
|
@ -314,13 +315,14 @@ func init() {
|
||||||
ixs := []lib.StrSlice{hf}
|
ixs := []lib.StrSlice{hf}
|
||||||
ixs = append(ixs, lib.StrSlice{"userName"})
|
ixs = append(ixs, lib.StrSlice{"userName"})
|
||||||
container_definition = &ContDef{
|
container_definition = &ContDef{
|
||||||
Prefix: type_prefix,
|
Prefix: type_prefix,
|
||||||
ContFactory: Tracks,
|
ContFactory: Tracks,
|
||||||
ItemFactory: MakeTrack,
|
ItemFactory: MakeTrack,
|
||||||
TableName: "tracks",
|
TableName: "tracks",
|
||||||
HeadFields: hf,
|
HeadFields: hf,
|
||||||
IdFields: hf,
|
IdFields: hf,
|
||||||
Indexes: ixs,
|
Indexes: ixs,
|
||||||
|
InsertOnChange: true,
|
||||||
}
|
}
|
||||||
RegisterContainerDef(container_definition)
|
RegisterContainerDef(container_definition)
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,12 +70,12 @@ func RepTest(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func JsonTest(t *testing.T) {
|
func JsonTest(t *testing.T) {
|
||||||
j := `[4, 2, "+"]`
|
j := `[4, 2, +]`
|
||||||
src := rep.ParseJson(j)
|
src := rep.ParseJson(j)
|
||||||
c := src.Compile(fe)
|
c := src.Compile(fe)
|
||||||
fe.Call(c)
|
fe.Call(c)
|
||||||
t.AssertEqual(fe.Pop(), 6)
|
t.AssertEqual(fe.Pop(), 6)
|
||||||
j = `{"firstname": "John", "lastname": "Dow"}`
|
j = `{firstname: John, lastname: Dow}`
|
||||||
prep := rep.ParseJsonTo[Person](j)
|
prep := rep.ParseJsonTo[Person](j)
|
||||||
person := prep.(*rep.Record).Data().(Person)
|
person := prep.(*rep.Record).Data().(Person)
|
||||||
t.AssertEqual(person.FirstName, "John")
|
t.AssertEqual(person.FirstName, "John")
|
||||||
|
|
Loading…
Add table
Reference in a new issue