From 00a6e70430b641cfd40782bdeb43e5272acf18cc Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Fri, 19 Apr 2024 10:42:54 +0200 Subject: [PATCH] use yaml for parsing JSON - works without quotes on simple strings --- forge/rep/json.go | 3 ++- go.mod | 3 +-- go.sum | 2 -- storage/message/message.go | 15 ++++++++------- storage/tracking/tracking.go | 30 ++++++++++++++++-------------- tests/forge_test.go | 4 ++-- 6 files changed, 29 insertions(+), 28 deletions(-) diff --git a/forge/rep/json.go b/forge/rep/json.go index 0a5ce15..6b783c4 100644 --- a/forge/rep/json.go +++ b/forge/rep/json.go @@ -1,7 +1,8 @@ package rep import ( - "encoding/json" + //"encoding/json" + json "gopkg.in/yaml.v3" "git.sr.ht/~cco/go-scopes/logging/log" ) diff --git a/go.mod b/go.mod index 395905a..a0a4c16 100644 --- a/go.mod +++ b/go.mod @@ -6,8 +6,8 @@ require ( github.com/gin-gonic/gin v1.9.1 github.com/lib/pq v1.10.9 github.com/rs/zerolog v1.29.1 - golang.org/x/exp v0.0.0-20230725093048-515e97ebf090 golang.org/x/net v0.10.0 + gopkg.in/yaml.v3 v3.0.1 modernc.org/sqlite v1.25.0 ) @@ -41,7 +41,6 @@ require ( golang.org/x/text v0.9.0 // indirect golang.org/x/tools v0.6.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 modernc.org/cc/v3 v3.40.0 // indirect modernc.org/ccgo/v3 v3.16.13 // indirect diff --git a/go.sum b/go.sum index 98cda55..a8850a9 100644 --- a/go.sum +++ b/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/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= 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/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= diff --git a/storage/message/message.go b/storage/message/message.go index 84d169d..39cf5b0 100644 --- a/storage/message/message.go +++ b/storage/message/message.go @@ -61,13 +61,14 @@ func init() { ixs := []lib.StrSlice{hf} ixs = append(ixs, lib.StrSlice{"domain", "class", "item"}) container_definition = &tracking.ContDef{ - Prefix: type_prefix, - ContFactory: Messages, - ItemFactory: MakeMessage, - TableName: "messages", - HeadFields: hf, - IdFields: hf, - Indexes: ixs, + Prefix: type_prefix, + ContFactory: Messages, + ItemFactory: MakeMessage, + TableName: "messages", + HeadFields: hf, + IdFields: hf, + Indexes: ixs, + InsertOnChange: true, } tracking.RegisterContainerDef(container_definition) } diff --git a/storage/tracking/tracking.go b/storage/tracking/tracking.go index 7eacdfd..ddb07d8 100644 --- a/storage/tracking/tracking.go +++ b/storage/tracking/tracking.go @@ -85,13 +85,14 @@ func (tr *Track) ScanP(rows *sql.Rows) error { // basic container implementation type ContDef struct { - Prefix string - ContFactory ContFactory - ItemFactory ItemFactory - TableName string - HeadFields lib.StrSlice - IdFields lib.StrSlice - Indexes []lib.StrSlice + Prefix string + ContFactory ContFactory + ItemFactory ItemFactory + TableName string + HeadFields lib.StrSlice + IdFields lib.StrSlice + Indexes []lib.StrSlice + InsertOnChange bool } type Container struct { @@ -314,13 +315,14 @@ func init() { ixs := []lib.StrSlice{hf} ixs = append(ixs, lib.StrSlice{"userName"}) container_definition = &ContDef{ - Prefix: type_prefix, - ContFactory: Tracks, - ItemFactory: MakeTrack, - TableName: "tracks", - HeadFields: hf, - IdFields: hf, - Indexes: ixs, + Prefix: type_prefix, + ContFactory: Tracks, + ItemFactory: MakeTrack, + TableName: "tracks", + HeadFields: hf, + IdFields: hf, + Indexes: ixs, + InsertOnChange: true, } RegisterContainerDef(container_definition) } diff --git a/tests/forge_test.go b/tests/forge_test.go index 848ad2a..67e0585 100644 --- a/tests/forge_test.go +++ b/tests/forge_test.go @@ -70,12 +70,12 @@ func RepTest(t *testing.T) { } func JsonTest(t *testing.T) { - j := `[4, 2, "+"]` + j := `[4, 2, +]` src := rep.ParseJson(j) c := src.Compile(fe) fe.Call(c) t.AssertEqual(fe.Pop(), 6) - j = `{"firstname": "John", "lastname": "Dow"}` + j = `{firstname: John, lastname: Dow}` prep := rep.ParseJsonTo[Person](j) person := prep.(*rep.Record).Data().(Person) t.AssertEqual(person.FirstName, "John")