Skip to content

Commit 66511f3

Browse files
authored
chore: use derive for eq checks (#3521)
1 parent 5a320e2 commit 66511f3

File tree

8 files changed

+227
-83
lines changed

8 files changed

+227
-83
lines changed

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ require (
111111
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
112112
github.com/authzed/authzed-go v1.4.1 // indirect
113113
github.com/authzed/grpcutil v0.0.0-20250221190651-1985b19b35b8 // indirect
114+
github.com/awalterschulze/goderive v0.5.1 // indirect
114115
github.com/bhmj/xpression v0.9.4 // indirect
115116
github.com/bitfield/gotestdox v0.2.2 // indirect
116117
github.com/bmatcuk/doublestar v1.3.4 // indirect
@@ -150,6 +151,7 @@ require (
150151
github.com/jonboulle/clockwork v0.5.0 // indirect
151152
github.com/jzelinskie/stringz v0.0.3 // indirect
152153
github.com/kevinburke/ssh_config v1.2.0 // indirect
154+
github.com/kisielk/gotool v1.0.0 // indirect
153155
github.com/klauspost/asmfmt v1.3.2 // indirect
154156
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8 // indirect
155157
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3 // indirect
@@ -532,6 +534,7 @@ require (
532534
)
533535

534536
tool (
537+
github.com/awalterschulze/goderive
535538
github.com/google/wire/cmd/wire
536539
github.com/jmattheis/goverter/cmd/goverter
537540
github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen

go.sum

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,8 @@ github.com/authzed/grpcutil v0.0.0-20250221190651-1985b19b35b8 h1:y17oq4U8n+k1Oc
864864
github.com/authzed/grpcutil v0.0.0-20250221190651-1985b19b35b8/go.mod h1:Pf1ZSi41EePvx1GC1DeEJw5dn35iUcxZHqpHuG1Rpic=
865865
github.com/avast/retry-go/v4 v4.7.0 h1:yjDs35SlGvKwRNSykujfjdMxMhMQQM0TnIjJaHB+Zio=
866866
github.com/avast/retry-go/v4 v4.7.0/go.mod h1:ZMPDa3sY2bKgpLtap9JRUgk2yTAba7cgiFhqxY2Sg6Q=
867+
github.com/awalterschulze/goderive v0.5.1 h1:H2XNRDw0Ordwj/pgLAVqQgDC1LQWP7L99ofOs72bjqg=
868+
github.com/awalterschulze/goderive v0.5.1/go.mod h1:DLlff0SRVo846CBrp8nXuXJ4mdWA92ai5CYTr+LV/II=
867869
github.com/aws/aws-lambda-go v1.49.0 h1:z4VhTqkFZPM3xpEtTqWqRqsRH4TZBMJqTkRiBPYLqIQ=
868870
github.com/aws/aws-lambda-go v1.49.0/go.mod h1:dpMpZgvWx5vuQJfBt0zqBha60q7Dd7RfgJv23DymV8A=
869871
github.com/aws/aws-sdk-go v1.15.27/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0=
@@ -1797,6 +1799,7 @@ github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF
17971799
github.com/keybase/go-keychain v0.0.1 h1:way+bWYa6lDppZoZcgMbYsvC7GxljxrskdNInRtuthU=
17981800
github.com/keybase/go-keychain v0.0.1/go.mod h1:PdEILRW3i9D8JcdM+FmY6RwkHGnhHxXwkPPMeUgOK1k=
17991801
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
1802+
github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg=
18001803
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
18011804
github.com/klauspost/asmfmt v1.3.2 h1:4Ri7ox3EwapiOjCki+hw14RyKk201CN4rzyCJRFLpK4=
18021805
github.com/klauspost/asmfmt v1.3.2/go.mod h1:AG8TuvYojzulgDAMCnYn50l/5QV3Bs/tp6j0HLHbNSE=
@@ -2002,8 +2005,6 @@ github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4=
20022005
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
20032006
github.com/oklog/ulid/v2 v2.1.1 h1:suPZ4ARWLOJLegGFiZZ1dFAkqzhMjL3J1TzI+5wHz8s=
20042007
github.com/oklog/ulid/v2 v2.1.1/go.mod h1:rcEKHmBBKfef9DhnvX7y1HZBYxjXb0cP5ExxNsTT1QQ=
2005-
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
2006-
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
20072008
github.com/oliveagle/jsonpath v0.0.0-20180606110733-2e52cf6e6852 h1:Yl0tPBa8QPjGmesFh1D0rDy+q1Twx6FyU7VWHi8wZbI=
20082009
github.com/oliveagle/jsonpath v0.0.0-20180606110733-2e52cf6e6852/go.mod h1:eqOVx5Vwu4gd2mmMZvVZsgIqNSaW3xxRThUJ0k/TPk4=
20092010
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=

openmeter/billing/derived.gen.go

Lines changed: 186 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

openmeter/billing/generate.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package billing
2+
3+
//go:generate go run github.com/awalterschulze/goderive

openmeter/billing/invoicedetailedline.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package billing
33
import (
44
"errors"
55
"fmt"
6-
"reflect"
76
"slices"
87

98
"github.com/alpacahq/alpacadecimal"
@@ -115,7 +114,7 @@ func (l DetailedLineBase) Clone() DetailedLineBase {
115114
}
116115

117116
func (l DetailedLineBase) Equal(other DetailedLineBase) bool {
118-
return reflect.DeepEqual(l, other)
117+
return deriveEqualDetailedLineBase(&l, &other)
119118
}
120119

121120
type DetailedLine struct {

openmeter/billing/invoiceline.go

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package billing
33
import (
44
"errors"
55
"fmt"
6-
"reflect"
76
"slices"
87
"sort"
98
"strings"
@@ -17,7 +16,6 @@ import (
1716
"github.com/openmeterio/openmeter/openmeter/productcatalog"
1817
"github.com/openmeterio/openmeter/openmeter/streaming"
1918
"github.com/openmeterio/openmeter/pkg/currencyx"
20-
"github.com/openmeterio/openmeter/pkg/equal"
2119
"github.com/openmeterio/openmeter/pkg/models"
2220
"github.com/openmeterio/openmeter/pkg/timeutil"
2321
)
@@ -125,7 +123,7 @@ type LineBase struct {
125123
}
126124

127125
func (i LineBase) Equal(other LineBase) bool {
128-
return reflect.DeepEqual(i, other)
126+
return deriveEqualLineBase(&i, &other)
129127
}
130128

131129
func (i LineBase) GetParentID() (string, bool) {
@@ -647,35 +645,7 @@ type UsageBasedLine struct {
647645
}
648646

649647
func (i UsageBasedLine) Equal(other *UsageBasedLine) bool {
650-
if other == nil {
651-
return false
652-
}
653-
654-
if !i.Price.Equal(other.Price) {
655-
return false
656-
}
657-
658-
if i.FeatureKey != other.FeatureKey {
659-
return false
660-
}
661-
662-
if !equal.PtrEqual(i.Quantity, other.Quantity) {
663-
return false
664-
}
665-
666-
if !equal.PtrEqual(i.MeteredQuantity, other.MeteredQuantity) {
667-
return false
668-
}
669-
670-
if !equal.PtrEqual(i.PreLinePeriodQuantity, other.PreLinePeriodQuantity) {
671-
return false
672-
}
673-
674-
if !equal.PtrEqual(i.MeteredPreLinePeriodQuantity, other.MeteredPreLinePeriodQuantity) {
675-
return false
676-
}
677-
678-
return true
648+
return deriveEqualUsageBasedLine(&i, other)
679649
}
680650

681651
func (i UsageBasedLine) Clone() *UsageBasedLine {

0 commit comments

Comments
 (0)