Skip to content
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

lool #182

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

lool #182

Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion precode.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ func postTask(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
if _, ex := tasks[task.ID]; ex {
http.Error(w, "Задача с таким ID уже существует", http.StatusConflict)

Choose a reason for hiding this comment

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

Форматирование съехало, рекомендую добавить go fmt в настройки IDE, в автозапуск при сохранении

Copy link
Author

Choose a reason for hiding this comment

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

Форматирование съехало, рекомендую добавить go fmt в настройки IDE, в автозапуск при сохранении

Спасибо за фичу. Учту в следующих проектах.

return
}

tasks[task.ID] = task

Choose a reason for hiding this comment

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

Перед этой операцией полезно добавить проверку - есть ли уже такой ID. И если да - вернуть ошибку пользователю. Иначе задача может быть перезатерта

Copy link
Author

Choose a reason for hiding this comment

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

Логично.


w.Header().Set("Content-Type", "application/json")
Expand All @@ -99,7 +104,7 @@ func getTaskForId(w http.ResponseWriter, r *http.Request) {
if err != nil {
fmt.Printf("Ошибка записи: %v", err)
}
json.NewEncoder(w).Encode(task)

Choose a reason for hiding this comment

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

Пустую строчку можно совсем убрать

}

// обработчик 4
Expand Down