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

Iter13 #13

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

Iter13 #13

wants to merge 50 commits into from

Conversation

shilin-anton
Copy link
Owner

Add uniqueness validation for DB and some refactoring

@shilin-anton shilin-anton requested a review from Bazys May 20, 2024 16:15
Copy link
Collaborator

@avhitrov avhitrov left a comment

Choose a reason for hiding this comment

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

  1. Необходимо изменить источник контекста для БД-функций.
  2. Следует унифицировать интерфейса стораджей
  3. Предлагаю скомпилировать с ключом -race и побомбить сервер на предмет гонок, взяв скрипт отсюда: https://github.com/avhitrov/shorterbomber

return &DataBase{DB: db}, err
}

func (db *DataBase) AddRecord(short, url string) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
func (db *DataBase) AddRecord(short, url string) error {
func (db *DataBase) AddRecord(ctx context.Context, short, url string) error {

Контекст здесь и везде в функциях, обрабатывающих пользовательские запросы, необходимо брать из контекста http-запроса (r.Context()), а не из воздyха. Соответственно, это должно отразиться и в интерфейсе.


var currentStorageType int

func (s Storage) Add(short, url string) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Гораздо правильнее будет реализовать единый интерфейс для разных стораджей (in-memory, file, db) и в момент инициализации определять по конфигурации, какой сторадж будет использоваться, инициализировать этот сторадж и скармливать его приемнику интерфейс в сервис или хендлер.

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