-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hw09 struct validator #9
Conversation
…d edit rulesRules map
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Спасибо за выполненное задание. Хорошая работа
Итого: 10 баллов из 10. Принято
var ( | ||
// целое не может быть меньше условия. | ||
ErrIntCantBeLess = errors.New("cannot be less") | ||
// целое не содержит совпадений с регулярным выражением. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Комментарий не совпадает с содержимым переменной
|
||
func (v ValidationErrors) Error() string { | ||
cnt := len(v) | ||
if cnt < 1 { | ||
return "" | ||
} | ||
return fmt.Sprintf("%d structure validation errors found", cnt) | ||
|
||
return func() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не понинаю, для чего обернуто в дополнительную функцию
"len": func(v reflect.Value, condition string) error { | ||
c, err := strconv.Atoi(condition) | ||
if err != nil { | ||
// 'condition' недопустимое условие для правила 'len'. | ||
return fmt.Errorf("'%s' %w '%s'", condition, ErrInvalidCond, "len") | ||
} | ||
|
||
if utf8.RuneCountInString(v.String()) != c { | ||
return ValidationError{ | ||
Err: fmt.Errorf("%w %s", ErrStrLenNotEqual, condition), | ||
} | ||
} | ||
return nil | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Можно выделить в самостоятельные функции, чтобы удобнее читать мапу с набором доступных валидаторов
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это решение сознательное. Чтобы по типу и правилу сразу увидеть функцию-валидатор.
hw09_struct_validator/validator.go
Outdated
if nested { | ||
return validateStructF(fieldValue, rules) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Можно перенести в цикл и убрать переменную nested
Домашнее задание №9 «Валидатор структур»
Чек-лист студента (Что это?)
go mod tidy
..sync
файл. Зачем его удалять?Критерии оценки
Зачёт от 7 баллов