Skip to content

Commit b2d5112

Browse files
authored
Merge pull request #159 from vgogolev1703/patch-1
Revert "fix: *string(nil) not equal &string #152"
2 parents 194d97e + 695454b commit b2d5112

File tree

2 files changed

+3
-47
lines changed

2 files changed

+3
-47
lines changed

values.go

+3-15
Original file line numberDiff line numberDiff line change
@@ -161,22 +161,10 @@ func ReadOnly(ctx context.Context, path, in string, data interface{}) *errors.Va
161161
func Required(path, in string, data interface{}) *errors.Validation {
162162
val := reflect.ValueOf(data)
163163
if val.IsValid() {
164-
typ := reflect.TypeOf(data)
165-
switch typ.Kind() {
166-
case reflect.Pointer:
167-
if val.IsNil() {
168-
return errors.Required(path, in, data)
169-
}
170-
if reflect.DeepEqual(reflect.Zero(val.Elem().Type()).Interface(), val.Elem().Interface()) {
171-
return errors.Required(path, in, data)
172-
}
173-
return nil
174-
default:
175-
if reflect.DeepEqual(reflect.Zero(val.Type()).Interface(), val.Interface()) {
176-
return errors.Required(path, in, data)
177-
}
178-
return nil
164+
if reflect.DeepEqual(reflect.Zero(val.Type()).Interface(), val.Interface()) {
165+
return errors.Required(path, in, data)
179166
}
167+
return nil
180168
}
181169
return errors.Required(path, in, data)
182170
}

values_test.go

-32
Original file line numberDiff line numberDiff line change
@@ -195,54 +195,22 @@ func TestValues_ValidateRequired(t *testing.T) {
195195
path := "test"
196196
in := "body"
197197

198-
emptyString := ""
199-
emptyStringStruct := struct {
200-
A *string
201-
}{
202-
A: &emptyString,
203-
}
204-
205-
emptyNumber := 0
206-
emptyNumberStruct := struct {
207-
A *int
208-
}{
209-
A: &emptyNumber,
210-
}
211-
212198
RequiredFail := []interface{}{
213199
"",
214200
0,
215201
nil,
216-
emptyStringStruct.A,
217-
emptyNumberStruct.A,
218202
}
219203

220204
for _, v := range RequiredFail {
221205
err = Required(path, in, v)
222206
assert.Error(t, err)
223207
}
224208

225-
notEmptyString := "bla"
226-
notEmptyStringStruct := struct {
227-
A *string
228-
}{
229-
A: &notEmptyString,
230-
}
231-
232-
notEmptyNumber := 1
233-
notEmptyNumberStruct := struct {
234-
A *int
235-
}{
236-
A: &notEmptyNumber,
237-
}
238-
239209
RequiredSuccess := []interface{}{
240210
" ",
241211
"bla-bla-bla",
242212
2,
243213
[]interface{}{21, []int{}, "testString"},
244-
notEmptyStringStruct.A,
245-
notEmptyNumberStruct.A,
246214
}
247215

248216
for _, v := range RequiredSuccess {

0 commit comments

Comments
 (0)