Skip to content

Commit

Permalink
make linter happy
Browse files Browse the repository at this point in the history
  • Loading branch information
lovromazgon committed Dec 21, 2023
1 parent c6678da commit 401e574
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
23 changes: 16 additions & 7 deletions opencdc/fromjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

package opencdc

import "github.com/goccy/go-json"
import (
"fmt"

"github.com/goccy/go-json"
)

func (r *Record) UnmarshalJSON(b []byte) error {
var raw struct {
Expand All @@ -30,7 +34,7 @@ func (r *Record) UnmarshalJSON(b []byte) error {

err := json.Unmarshal(b, &raw)
if err != nil {
return err
return err //nolint:wrapcheck // no additional context to add
}

key, err := dataUnmarshalJSON(raw.Key)
Expand Down Expand Up @@ -64,10 +68,15 @@ func dataUnmarshalJSON(b []byte) (Data, error) {
if b[0] == '"' {
var data RawData
err := json.Unmarshal(b, &data)
return data, err
} else {
var data StructuredData
err := json.Unmarshal(b, &data)
return data, err
if err != nil {
return nil, fmt.Errorf("failed to unmarshal raw data: %w", err)
}
return data, nil
}
var data StructuredData
err := json.Unmarshal(b, &data)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal structured data: %w", err)
}
return data, nil
}
26 changes: 24 additions & 2 deletions opencdc/fromjson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

func TestRecord_UnmarshalJSON(t *testing.T) {
is := is.New(t)
want := Record{
have := Record{
Position: Position("standing"),
Operation: OperationUpdate,
Metadata: Metadata{"foo": "bar"},
Expand All @@ -46,7 +46,29 @@ func TestRecord_UnmarshalJSON(t *testing.T) {
},
},
}
b, err := json.Marshal(want)
want := Record{
Position: Position("standing"),
Operation: OperationUpdate,
Metadata: Metadata{"foo": "bar"},
Key: RawData("padlock-key"),
Payload: Change{
Before: RawData("yellow"),
After: StructuredData{
"bool": true,

"int": 1.0,
"int32": 1.0,
"int64": 1.0,

"float32": 1.2,
"float64": 1.2,

"string": "orange",
},
},
}

b, err := json.Marshal(have)
is.NoErr(err)

var got Record
Expand Down

0 comments on commit 401e574

Please sign in to comment.