-
Notifications
You must be signed in to change notification settings - Fork 310
rabotaet #220
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
base: main
Are you sure you want to change the base?
rabotaet #220
Conversation
dirtymew
left a comment
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.
Привет
стало лучше но PR оформлен все еще неверно - он должен быть в твой форк а не репозиторий задания
по реализации есть замечания - см комментарии
| } | ||
| w.Header().Set("Content-Type", "application/json") | ||
| w.WriteHeader(http.StatusOK) | ||
| w.Write(resp) |
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.
_ , _ = w.Write(resp)
тут стоит либо явно проигнорировать ошибку или ее логировать
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.
@artwovk прошу прощения упустил вопрос потому, что PR был другой отправлен в следующую итерацию ревью
работа с ошибками это очень важная особенность программирования на go
если функция возвращает ошибку ее принято обработать например
if _ , err := w.Write(resp); err != nil {
...
}
в данной конкретно ситуации если ошибка из функции w.Write мы уже не сможем вернуть ответ на запрос пользователя - так как ошибка при записи тела ответа
поэтому либо явно игнорируем ее _ , _ = w.Write(resp) - такая конструкция говорит о том что разработчик в курсе что функция возвращает ошибку и сознательно ее игнорирует
либо логируем например так
if _ , err := w.Write(resp); err != nil {
log.Print(err)
}
| } | ||
|
|
||
| func postZad(w http.ResponseWriter, r *http.Request) { | ||
| var zad Task |
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.
названия переменным нужно выбирать так чтобы они несли какой то смысл
не стоит использовать сокращения и транслитерацию
var task Task
| w.Write(resp) | ||
| } | ||
|
|
||
| func postZad(w http.ResponseWriter, r *http.Request) { |
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.
addTask
| w.WriteHeader(http.StatusCreated) | ||
| } | ||
|
|
||
| func getZad(w http.ResponseWriter, r *http.Request) { |
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.
getTask
| // Ниже напишите обработчики для каждого эндпоинта | ||
| // ... | ||
|
|
||
| func getVse(w http.ResponseWriter, r *http.Request) { |
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.
getTasks
| w.Write(resp) | ||
| } | ||
|
|
||
| func delZad(w http.ResponseWriter, r *http.Request) { |
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.
deleteTasks
| http.Error(w, err.Error(), http.StatusBadRequest) | ||
| return | ||
| } | ||
| tasks[zad.ID] = zad |
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.
Можно, пожалуйста, ссылку на урок, где нас этому учат?
Я не нашёл информации.
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.
@artwovk чему? как проверить есть ли ключ в мапе? ну так я понимаю с этим нет проблем на 96 ты это делаешь.
или тому добавить не равно изменить? тут ответ ожидается http.StatusCreated - что подразумевает добавление чего то - да и в задании так описано
No description provided.