Skip to content

Final project#2#1

Open
bear-brown-beard wants to merge 6 commits intomainfrom
final_project
Open

Final project#2#1
bear-brown-beard wants to merge 6 commits intomainfrom
final_project

Conversation

@bear-brown-beard
Copy link
Copy Markdown
Owner

No description provided.

Copy link
Copy Markdown

@ivannizh ivannizh left a comment

Choose a reason for hiding this comment

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

Михаил, привет!

Хорошая выпускная работа, всё работает и тесты проходят.
Код написан хорошо, критических замечаний нет, но хорошо бы поправить проблему с потерей ошибок.
Также можно почитать и попробовать переделать код на слои, можно прочитать про организацию кода в Go, например, на Хабре.

Работу принимаю и желаю успехов в дальнейшем изучении и применении Go!

Comment thread Dockerfile
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Хороший докерфайл

Comment thread app
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Бинари лучше не класть в репозиторий, они занимают много места, от них потом не избавишься, а толку от них мало.

Comment thread main.go

http.HandleFunc("/api/nextdate", nextDateHandler)
http.HandleFunc("/api/task", func(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodPost {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Немного перегружен main
Обработку типа запроса можно делать в самой функции, а для такого ветвления можно было сделать отдельную функцию.

Так же проще этот if else заменить на switch case

Comment thread main.go
}
})

log.Printf("Server running http://localhost%s\n", port)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Хороший лог

Comment thread main.go
http.Error(w, `{"error":"Не указан ID задачи"}`, http.StatusBadRequest)
}
} else if r.Method == http.MethodPut {
handleUpdateTask(w, r, db)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Правильно, что передаешь один коннект к БД во все хендлеры, а то часто студенты на каждый запрос создают коннект.

Comment thread tasks.go
var task Task

if err := json.NewDecoder(r.Body).Decode(&task); err != nil {
http.Error(w, `{"error":"Ошибка десериализации JSON"}`, http.StatusBadRequest)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Теряешь сообщение об ошибки, нужно либо клиенту его вернуть, либо в лог вывести. Второй вариант лучше

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Это у тебя по всему коду

Comment thread tasks.go
}

tasks = append(tasks, task)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

После цикла нужно проверить курсор на наличие ошибок

http://go-database-sql.org/retrieving.html

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