Repository navigation
Conversation
|
|
||
| var resp []handler.ItemBatchResponse | ||
| json.Unmarshal(w.Body.Bytes(), &resp) | ||
| _ = json.Unmarshal(w.Body.Bytes(), &resp) |
There was a problem hiding this comment.
Если не обрабатываешь ошибку - как будто и не смысла возвращать _
|
|
||
| // InsertURLsBatch вставляет набор URL в БД одним batch-запросом. | ||
| func (r *Repository) InsertURLsBatch(ctx context.Context, data []repository.Data) error { | ||
| if len(data) == 0 { |
There was a problem hiding this comment.
Как будто это проверку стоит делать на слое выше - то есть на сервисе
Чтобы не ходить сюда лишний раз
|
|
||
| for userID, urls := range urlsByUser { | ||
| query := ` | ||
| UPDATE urls |
There was a problem hiding this comment.
Или можешь попробовать конструктор запросов https://github.com/Masterminds/squirrel
Я пользуюсь ей - удобная штука
| } | ||
|
|
||
| // GetURLByShortURL получает URL по короткой ссылке | ||
| func (r *Repository) GetURLByShortURL(ctx context.Context, shortURL string) (repository.Data, error) { |
| bufferSize int | ||
| flushInterval time.Duration | ||
| logger *zap.SugaredLogger | ||
| ctx context.Context |
There was a problem hiding this comment.
Контекст не хранят в структурах, а прокидывают сверху
Это написано в самом пакете
// Do not store Contexts inside a struct type; instead, pass a Context
// explicitly to each function that needs it. This is discussed further in
// https://go.dev/blog/context-and-structs. The Context should be the first
// parameter, typically named ctx:
//
// func DoSomething(ctx context.Context, arg Arg) error {
// // ... use ctx ...
// }
|
|
||
| // Start запускает воркер: объединяет входные каналы и начинает обработку удалений. | ||
| func (w *DeleteWorker) Start() { | ||
| mergedChan := w.fanIn(w.inputChannels...) |
| return &HTTPObserver{ | ||
| url: url, | ||
| client: &http.Client{ | ||
| Timeout: 5 * time.Second, |
| func NewHTTPObserver(url string) *HTTPObserver { | ||
| return &HTTPObserver{ | ||
| url: url, | ||
| client: &http.Client{ |
There was a problem hiding this comment.
Можешь попробовать клиент resty - мощная штука + плюс придется писать меньше кода
added link flag