Skip to content

Commit eb7113d

Browse files
Some review Comments
Signed-off-by: Yogesh Deshpande <[email protected]>
1 parent 8bd66e5 commit eb7113d

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

cmw.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ func (o CMW) GetCollectionItem(key any) (*CMW, error) {
153153
return o.collection.getItem(key)
154154
}
155155

156+
// ValidateCollection is now deprecated
157+
// use Valid() instead
156158
func (o CMW) ValidateCollection() error {
157159
if o.kind != KindCollection {
158160
return fmt.Errorf("want collection, got %q", o.kind)
@@ -166,7 +168,7 @@ func (o CMW) Valid() error {
166168
case KindMonad:
167169
return o.monad.valid()
168170
case KindCollection:
169-
return o.ValidateCollection()
171+
return o.validate()
170172
default:
171173
return fmt.Errorf("unknown kind: %s", o.kind.String())
172174
}

collection.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,17 @@ func (o collection) validate() error {
3030
}
3131

3232
for k, v := range o.cmap {
33-
if v.kind != KindCollection {
34-
continue
35-
}
36-
if err := v.validate(); err != nil {
37-
return fmt.Errorf("invalid collection at key %q: %w", k, err)
33+
switch v.kind {
34+
case KindMonad:
35+
if err := v.monad.valid(); err != nil {
36+
return fmt.Errorf("invalid monad at key %q: %w", k, err)
37+
}
38+
case KindCollection:
39+
if err := v.validate(); err != nil {
40+
return fmt.Errorf("invalid collection at key %q: %w", k, err)
41+
}
42+
default:
43+
return fmt.Errorf("invalid kind niether monad nor collection: %s", v.kind.String())
3844
}
3945
}
4046

example_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,7 @@ func Example_roundtrip_JSON_collection() {
147147
if err != nil {
148148
log.Fatalf("unmarshal JSON collection failed: %v", err)
149149
}
150-
err = o.ValidateCollection()
151-
if err != nil {
152-
log.Fatalf("validate JSON collection failed: %v", err)
153-
}
150+
154151
b, err := o.MarshalJSON()
155152
if err != nil {
156153
log.Fatalf("marshal collection to JSON failed: %v", err)

monad.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (o *monad) UnmarshalJSON(b []byte) error {
2929

3030
o.format = FormatJSONRecord
3131

32-
return o.valid()
32+
return nil
3333
}
3434

3535
func (o monad) MarshalCBOR() ([]byte, error) {
@@ -60,7 +60,7 @@ func (o *monad) UnmarshalCBOR(b []byte) error {
6060
panic(fmt.Sprintf("want CBOR Tag or CBOR array, got 0x%02x", b[0]))
6161
}
6262

63-
return o.valid()
63+
return nil
6464
}
6565

6666
func (o monad) valid() error {

monad_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ func Test_Deserialize_monad_ok(t *testing.T) {
8888

8989
err := actual.Deserialize(tt.tv)
9090
assert.NoError(t, err)
91-
err = actual.monad.valid()
92-
assert.NoError(t, err)
9391
assert.Equal(t, KindMonad, actual.GetKind())
9492
assert.Equal(t, tt.exp.format, actual.GetFormat())
9593
assert.Equal(t, tt.exp, actual.monad)

0 commit comments

Comments
 (0)