From 21fbe0a575890f220fee4daac39941e0b7d7d66d Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Sat, 11 Jul 2020 07:50:43 +0900 Subject: [PATCH] feat: change signature BREAKING CHANGE: the signature is changed --- dataeq/dataeq.go | 28 +++++++++++----------------- go.sum | 9 ++++----- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/dataeq/dataeq.go b/dataeq/dataeq.go index e3deff1..e350cd9 100644 --- a/dataeq/dataeq.go +++ b/dataeq/dataeq.go @@ -8,54 +8,48 @@ type ( Marshal func(interface{}) ([]byte, error) Unmarshal func([]byte, interface{}) error - DataFormat interface { - ConvertByte([]byte) (interface{}, error) - Convert(interface{}) (interface{}, error) - Equal(x, y interface{}) (bool, error) - } - - converter struct { + DataFormat struct { marshal func(interface{}) ([]byte, error) unmarshal func([]byte, interface{}) error } ) func New(marshal Marshal, unmarshal Unmarshal) DataFormat { - return &converter{ + return DataFormat{ marshal: marshal, unmarshal: unmarshal, } } -func (c *converter) ConvertByte(b []byte) (interface{}, error) { +func (df DataFormat) ConvertByte(b []byte) (interface{}, error) { var d interface{} - err := c.unmarshal(b, &d) + err := df.unmarshal(b, &d) if err == nil { return d, nil } return nil, err } -func (c *converter) Convert(x interface{}) (interface{}, error) { +func (df DataFormat) Convert(x interface{}) (interface{}, error) { if a, ok := x.([]byte); ok { - return c.ConvertByte(a) + return df.ConvertByte(a) } - b, err := c.marshal(x) + b, err := df.marshal(x) if err != nil { return nil, err } - return c.ConvertByte(b) + return df.ConvertByte(b) } -func (c *converter) Equal(x, y interface{}) (bool, error) { +func (df DataFormat) Equal(x, y interface{}) (bool, error) { if reflect.DeepEqual(x, y) { return true, nil } - a, err := c.Convert(x) + a, err := df.Convert(x) if err != nil { return false, err } - b, err := c.Convert(y) + b, err := df.Convert(y) if err != nil { return false, err } diff --git a/go.sum b/go.sum index 0d803dc..56d62e7 100644 --- a/go.sum +++ b/go.sum @@ -1,11 +1,10 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.6.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=