diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..9c69c17 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,33 @@ +name: go +on: + push: + branches: + - master + pull_request: + +permissions: + contents: read + +env: + GOPRIVATE: github.com/NextronSystems/ +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: stable + - name: Test + run: go test -v ./... + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: stable + - name: Lint + uses: golangci/golangci-lint-action@v8 + with: + version: v2.1.6 diff --git a/reference_test.go b/reference_test.go index 6bcf2c4..5a4291d 100644 --- a/reference_test.go +++ b/reference_test.go @@ -3,9 +3,82 @@ package jsonlog import ( "testing" + "github.com/NextronSystems/jsonlog/jsonpointer" "github.com/stretchr/testify/assert" ) +type testObject struct { + ObjectHeader + + Substruct struct { + SubField1 string `json:"subfield1" textlog:"subfield1"` + } `json:"substruct" textlog:"substruct,expand"` + + // nolint:unused // not used, just used to check that unexported fields are not included in the event + unexported string + + AnonymousSubstruct + + Nested NestedSubstruct `json:"nested" textlog:"nested,expand"` + + Unexpanded UnexpandedSubstruct `json:"unexpanded" textlog:"unexpanded"` + + Subfield5 string `json:"subfield5" textlog:"subfield5"` + + Valuer TestEventValuer `json:"valuer" textlog:"valuer"` + + SubObject *SubObject `json:"subobject" textlog:"subobject,expand"` +} + +type AnonymousSubstruct struct { + SubField2 string `json:"subfield2" textlog:"subfield2"` +} + +type NestedSubstruct struct { + Substruct struct { + SubField3 string `json:"subfield3" textlog:"subfield3"` + } `json:"substruct" textlog:",expand"` +} + +type UnexpandedSubstruct struct { + SubField4 string `json:"subfield4" textlog:"subfield4"` +} + +func (u UnexpandedSubstruct) String() string { + return u.SubField4 +} + +type TestEventValuer struct { + Subfield6 string `json:"subfield6"` + Subfield7 string `json:"subfield7"` + Ignore string +} + +func (t *TestEventValuer) RelativeTextPointer(pointee any) (string, bool) { + if pointee == &t.Subfield6 { + return "subfield6", true + } + if pointee == &t.Subfield7 { + return "subfield7", true + } + return "", false +} + +func (t *TestEventValuer) RelativeJsonPointer(pointee any) jsonpointer.Pointer { + if pointee == &t.Subfield6 { + return jsonpointer.New("subfield6") + } + if pointee == &t.Subfield7 { + return jsonpointer.New("subfield7") + } + return nil +} + +type SubObject struct { + ObjectHeader + Subfield8 string `json:"subfield8" textlog:"subfield8"` +} + func TestReference_ToJsonPointer(t *testing.T) { var test testObject test.Substruct.SubField1 = "subfield1" diff --git a/thorlog/jsonschema/go.mod b/thorlog/jsonschema/go.mod index e7935a5..70881db 100644 --- a/thorlog/jsonschema/go.mod +++ b/thorlog/jsonschema/go.mod @@ -1,9 +1,9 @@ -module gitlab.nextron/nextron-research/jsonlog/thorlog/jsonschema +module github.com/NextronSystems/jsonlog/thorlog/jsonschema go 1.23.1 require ( - github.com/NextronSystems/jsonlog v0.0.0-20240927093204-3ba6fa967aa2 + github.com/NextronSystems/jsonlog v0.0.0-20250522074152-0a205b123911 github.com/invopop/jsonschema v0.12.0 github.com/wk8/go-ordered-map/v2 v2.1.8 ) @@ -17,3 +17,5 @@ require ( golang.org/x/mod v0.15.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) + +replace github.com/NextronSystems/jsonlog => ../../ diff --git a/thorlog/jsonschema/go.sum b/thorlog/jsonschema/go.sum index 132cbca..1f4e659 100644 --- a/thorlog/jsonschema/go.sum +++ b/thorlog/jsonschema/go.sum @@ -1,5 +1,5 @@ -github.com/NextronSystems/jsonlog v0.0.0-20240927093204-3ba6fa967aa2 h1:Zf5UV/1V+wA0F9rrpLZRL0Fvxi+9WuD9a0KsKnrAnmE= -github.com/NextronSystems/jsonlog v0.0.0-20240927093204-3ba6fa967aa2/go.mod h1:Hk47VW018TX8o/0sxK+EJt16iRE7gB91zGZGiaAjcww= +github.com/NextronSystems/jsonlog v0.0.0-20250522074152-0a205b123911 h1:jmmvwkhul9DtWWOBhyeyXV9LA4cQzqJ0UyniD3e/HZQ= +github.com/NextronSystems/jsonlog v0.0.0-20250522074152-0a205b123911/go.mod h1:Hk47VW018TX8o/0sxK+EJt16iRE7gB91zGZGiaAjcww= github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk= github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg= github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs= diff --git a/thorlog/parser/parser.go b/thorlog/parser/parser.go index dd92e62..5184279 100644 --- a/thorlog/parser/parser.go +++ b/thorlog/parser/parser.go @@ -7,7 +7,7 @@ import ( "github.com/NextronSystems/jsonlog/thorlog/common" thorlogv1 "github.com/NextronSystems/jsonlog/thorlog/v1" thorlogv2 "github.com/NextronSystems/jsonlog/thorlog/v2" - "github.com/NextronSystems/jsonlog/thorlog/v3" + thorlogv3 "github.com/NextronSystems/jsonlog/thorlog/v3" ) func ParseEvent(data []byte) (common.Event, error) { @@ -32,7 +32,7 @@ func ParseEvent(data []byte) (common.Event, error) { } return &event, nil case common.JsonV3: - var logObject thorlog.EmbeddedObject + var logObject thorlogv3.EmbeddedObject if err := json.Unmarshal(data, &logObject); err != nil { return nil, err }