-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Iter13 #13
Conversation
Small storage fix
Remove storage import from file-manager, Change logic in main, Change code style in files, Remove server package, Fix tests
Separate filemanager layer from handlers, Improve filemanager handling in storage
Some code refactor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Необходимо изменить источник контекста для БД-функций.
- Следует унифицировать интерфейса стораджей
- Предлагаю скомпилировать с ключом
-race
и побомбить сервер на предмет гонок, взяв скрипт отсюда: https://github.com/avhitrov/shorterbomber
return &DataBase{DB: db}, err | ||
} | ||
|
||
func (db *DataBase) AddRecord(short, url string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Гораздо правильнее будет реализовать единый интерфейс для разных стораджей (in-memory, file, db) и в момент инициализации определять по конфигурации, какой сторадж будет использоваться, инициализировать этот сторадж и скармливать его приемнику интерфейс в сервис или хендлер.
Add uniqueness validation for DB and some refactoring