Skip to content

Commit 31acf86

Browse files
ivanmatmatioktalz
authored andcommitted
MINOR: remove Options from utils
1 parent bb41123 commit 31acf86

File tree

2 files changed

+0
-243
lines changed

2 files changed

+0
-243
lines changed

cmd/struct_equal_generator/utils.tmpl

Lines changed: 0 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,10 @@ import (
77
"unicode"
88
)
99

10-
11-
var NilSameAsEmpty = true
12-
var SkipIndex = true
13-
14-
type Options struct {
15-
NilSameAsEmpty bool
16-
SkipIndex bool
17-
}
18-
1910
func Ptr[V any](v V) *V {
2011
return &v
2112
}
2213

23-
func getOptions(opts ...Options) Options {
24-
if len(opts) == 0 {
25-
return Options{
26-
NilSameAsEmpty: NilSameAsEmpty,
27-
SkipIndex: SkipIndex,
28-
}
29-
}
30-
return opts[0]
31-
}
3214

3315
func equalPointers[T comparable](a, b *T) bool {
3416
if a == nil || b == nil {
@@ -37,117 +19,13 @@ func equalPointers[T comparable](a, b *T) bool {
3719
return *a == *b
3820
}
3921

40-
func CheckSameNilAndLen[T any](s,t []T, opts ...Options) bool {
41-
opt := getOptions(opts...)
42-
43-
if !opt.NilSameAsEmpty {
44-
if s == nil && t != nil {
45-
return false
46-
}
47-
if t == nil && s != nil {
48-
return false
49-
}
50-
}
51-
if len(s) != len(t) {
52-
return false
53-
}
54-
return true
55-
}
56-
57-
func CheckSameNilAndLenMap[S comparable, T any](s, t map[S]T, opts ...Options) bool {
58-
opt := getOptions(opts...)
59-
60-
if !opt.NilSameAsEmpty {
61-
if s == nil && t != nil {
62-
return false
63-
}
64-
if t == nil && s != nil {
65-
return false
66-
}
67-
}
68-
if len(s) != len(t) {
69-
return false
70-
}
71-
return true
72-
}
73-
74-
func equalComparableSlice[T comparable](s1, s2 []T, opt Options) bool {
75-
if !opt.NilSameAsEmpty {
76-
if s1 == nil && s2 != nil {
77-
return true
78-
}
79-
if s2 == nil && s1 != nil {
80-
return true
81-
}
82-
}
83-
if len(s1) != len(s2) {
84-
return false
85-
}
86-
for i, v1 := range s1 {
87-
if v1 != s2[i] {
88-
return false
89-
}
90-
}
91-
return true
92-
}
93-
94-
func equalComparableMap[T comparable](m1, m2 map[string]T, opt Options) bool {
95-
if !opt.NilSameAsEmpty {
96-
if m1 == nil && m2 != nil {
97-
return false
98-
}
99-
if m2 == nil && m1 != nil {
100-
return false
101-
}
102-
}
103-
if len(m1) != len(m2) {
104-
return false
105-
}
106-
for k, v1 := range m1 {
107-
v2, ok := m2[k]
108-
if !ok {
109-
return false
110-
}
111-
if v1 != v2 {
112-
return false
113-
}
114-
}
115-
return true
116-
}
117-
11822
func ValueOrNil[T any](v *T) any {
11923
if v == nil {
12024
return nil
12125
}
12226
return *v
12327
}
12428

125-
func equalMapStringMapSting(m1, m2 map[string]map[string]string, opt Options) bool {
126-
if !opt.NilSameAsEmpty {
127-
if m1 == nil && m2 != nil {
128-
return false
129-
}
130-
if m2 == nil && m1 != nil {
131-
return false
132-
}
133-
}
134-
135-
if len(m1) != len(m2) {
136-
return false
137-
}
138-
for k1, v1 := range m1 {
139-
if v2, ok := m2[k1]; !ok {
140-
return false
141-
} else {
142-
if !equalComparableMap(v1, v2, opt){
143-
return false
144-
}
145-
}
146-
}
147-
return true
148-
}
149-
150-
15129
func GetListOfFields(typ reflect.Type) []string {
15230
if typ.Kind() != reflect.Struct {
15331
return nil

models/utils_compare.go

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

0 commit comments

Comments
 (0)