Conversation
dirtymew
left a comment
There was a problem hiding this comment.
Привет Степан
хорошая работа - немного поправить и будет принята
| ) | ||
|
|
||
| func MainHandler(w http.ResponseWriter, r *http.Request) { | ||
| file, err := os.ReadFile("index.html") |
There was a problem hiding this comment.
тут можно проще http.ServeFile(w, r, "./index.html")
| import "errors" | ||
|
|
||
| var ( | ||
| ErrEmptyValue = errors.New("An empty value is received") |
| import "errors" | ||
|
|
||
| var ( | ||
| ErrEmptyValue = errors.New("An empty value is received") |
There was a problem hiding this comment.
и кажется это преждевременно
зачем выносить в отдельный пакет то что используется один раз
|
|
||
| serv := HttpServer{ | ||
| Loger: loger, Serv: &http.Server{ | ||
| Addr: ":8080", Handler: r, ErrorLog: loger, ReadTimeout: time.Duration(5) * time.Second, WriteTimeout: time.Duration(10) * time.Second, IdleTimeout: time.Duration(15) * time.Second, |
There was a problem hiding this comment.
лучше построчно перенести - так не читаемая строка получилась
|
|
||
| // Проверка строка содержит азбуку морзе. | ||
| func isMorseCode(data string) bool { | ||
| for _, val := range data { |
There was a problem hiding this comment.
есть полезные функции например strings.ContainsFunc
| } | ||
| w.Write([]byte(dataParsed + "\n")) | ||
| } | ||
| w.WriteHeader(http.StatusOK) |
There was a problem hiding this comment.
это нужно делать до записи в тело иначе будут сыпаться ошибки и код может клиент не получить
|
|
||
| w.Header().Set("Content-Type", "text/html") | ||
|
|
||
| for scanner.Scan() { |
There was a problem hiding this comment.
тут не нужен сканер - зачем?
читай сразу все боди - не нужно это делать построчно
это ошибка
если первая строка будет состоять из точки? то часть строк будет в морзе часть в тексте это неверная логика
| } | ||
|
|
||
| func UploadHandler(w http.ResponseWriter, r *http.Request) { | ||
| err := r.ParseMultipartForm(10) |
There was a problem hiding this comment.
это зачем? есть понимание что делает ParseMultipartForm и в какой размеренности его параметры?
| w.Write(file) | ||
| } | ||
|
|
||
| func UploadHandler(w http.ResponseWriter, r *http.Request) { |
There was a problem hiding this comment.
нужно метод запроса проверять или указать в роутере
| http.Error(w, "Ошибка при попытке загрузить файл", http.StatusInternalServerError) | ||
| return | ||
| } | ||
| fmt.Fprint(w, dataParsed) |
| } | ||
| defer fileNew.Close() | ||
|
|
||
| w.Header().Set("Content-Type", "text/html; charset=utf-8") |
There was a problem hiding this comment.
хедеры лучше поставить на 52 строке ниже
No description provided.