Skip to content

HW09 is completed#15

Open
ezhk wants to merge 6 commits intomasterfrom
hw09_generator_of_validators
Open

HW09 is completed#15
ezhk wants to merge 6 commits intomasterfrom
hw09_generator_of_validators

Conversation

@ezhk
Copy link
Copy Markdown
Owner

@ezhk ezhk commented Aug 22, 2020

Домашнее задание №9 «Генератор валидаторов»

Критерии оценки

  • Закоммичен сгенерированный код - 1 балл
  • Пайплайн зелёный - 3 балла
  • Добавлены новые юнит-тесты (доработаны имеющиеся) в models - до 2 баллов
  • Добавлены юнит-тесты для тулзы в go-validate - до 2 баллов
  • Понятность и чистота кода - до 2 баллов

Зачёт от 7 баллов

@ezhk ezhk changed the title Hw09 generator of validators HW09 is completed Aug 22, 2020
Copy link
Copy Markdown
Collaborator

@Antonboom Antonboom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://otus.ru/teacher-lk/homework/23752/7007/

Здравствуйте!
Отличная работа.

Принято
10 / 10

}

func ContainsInt(toFind int, searchingString string) bool {
for _, strValue := range strings.Split(searchingString, ",") {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. разделение стоит делать на этапе кодогенерации, чтобы валидатор сразу работал с []string и не тратил время на ресурсы

  2. при желании можно и мапу генерировать, чтобы в целом было O(1). правда N скорее всего мало, так что некритично

}

func (structName User) Validate() ([]ValidationError, error) {
errors := make([]ValidationError, 0)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

if structName.Age < 18 {
errors = append(errors, ValidationError{Field: "Age", Err: fmt.Errorf("invalid Age length")})
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

в ошибках не хватает ожидаемых и полученных значений

for _, value := range structName.Phones {

if len(value) != 11 {
errors = append(errors, ValidationError{Field: "Phones", Err: fmt.Errorf("invalid Phones length")})
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

в ошибке не хватает информации об индексе элемента

errors = append(errors, ValidationError{Field: "Age", Err: fmt.Errorf("invalid Age length")})
}

if re := regexp.MustCompile("^\\w+@\\w+\\.\\w+$"); re.FindString(string(structName.Email)) == "" {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

в продакшн-ready решении скорее всего пришлось бы компилировать регулярочки заранее (в var, например)

сейчас и так приемлимо.

validatedStruct := ValidateStruct(parsedStruct)
document, err := GenerateDocument(validatedStruct)
if err != nil {
fmt.Println(err)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log.Fatal?


require github.com/stretchr/testify v1.5.1
require (
github.com/fatih/structtag v1.2.0 // indirect
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

где он используется?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants