Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
MetalBlueberry committed May 19, 2024
1 parent b569814 commit c7622db
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
21 changes: 13 additions & 8 deletions types/arrayok.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,23 @@ func (arrayOK *ArrayOKfloat64) MarshalJSON() ([]byte, error) {
}

func (arrayOK *ArrayOKfloat64) UnmarshalJSON(data []byte) error {
arrayOK.Array = nil
arrayOK.Value = 0

var array []float64
err := json.Unmarshal(data, &array)
if err != nil {
var value float64
err := json.Unmarshal(data, &value)
if err != nil {
return err
}
arrayOK.Value = value
if err == nil {
arrayOK.Array = array
return nil
}
arrayOK.Array = array

var value float64
err = json.Unmarshal(data, &value)
if err != nil {
return err
}
arrayOK.Value = value
return nil
return nil

}
5 changes: 1 addition & 4 deletions types/arrayok_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ type TestMarshallScenario struct {
Expected string
}

func TestTypes(t *testing.T) {
}

func TestFloat64Marshal(t *testing.T) {
RegisterTestingT(t)

Expand Down Expand Up @@ -45,7 +42,7 @@ func TestFloat64Marshal(t *testing.T) {
}
for _, tt := range table {
t.Run(tt.Name, func(t *testing.T) {
result, err := json.Marshal(tt.Input)
result, err := json.Marshal(&tt.Input)
Expect(err).To(BeNil())
Expect(string(result)).To(Equal(tt.Expected))

Expand Down

0 comments on commit c7622db

Please sign in to comment.