-
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
Iter20: Указание версии приложения при сборке и вывод этой версии при старте приложения. #21
Conversation
…os.Exit() в пакете main
iter20: code coverage report
…ычислении покрытия
iter20: Покрыл юнит-тестами package: postgres
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 parseFlags(args []string, c *config.Agent) { | ||
fs := flag.NewFlagSet(args[0], flag.PanicOnError) | ||
fs.SetOutput(os.Stdout) | ||
fs.StringVar(&c.CollectorAddress, "a", "127.0.0.1:8080", "address server endpoint") |
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.
Используй константы вместо магических чисел для значений по умолчанию флагов
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_parseFlags(t *testing.T) { |
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.
Группируй связанные тестовые случаи в подтесты с помощью t.Run для улучшения структуры и читаемости тестов
fs.BoolVar(&c.Backup.Restore, "r", true, "Restore storage before start") | ||
fs.StringVar(&c.DB.DSN, "d", "", "Database DSN") | ||
fs.StringVar(&c.Hash.Key, "k", "", "SHA256 Key") | ||
if err := fs.Parse(args[1:]); err != nil { |
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.
Используй структурированную обработку ошибок вместо паники при ошибке парсинга флагов
flag.StringVar(&c.DB.DSN, "d", "", "Database DSN") | ||
flag.StringVar(&c.Hash.Key, "k", "", "SHA256 Key") | ||
flag.Parse() | ||
func parseFlags(args []string, c *config.Server) { |
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.
Создай отдельный пакет для обработки конфигурации, включая работу с флагами и переменными окружения
|
||
if _, err := db.ExecContext(ctx, schemaCounterSQL); err != nil { |
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.
лучше переименуй метод InitTables в CreateTablesIfNotExist для более точного описания его функции
"github.com/sirupsen/logrus" | ||
) | ||
|
||
type Build struct { |
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.
Переименуй структуру Build в VersionInfo для более точного отражения ее содержимого
|
||
if _, err := db.ExecContext(ctx, schemaCounterSQL); err != nil { |
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.
В методе InitTables можно использовать транзакцию для создания таблиц, чтобы обеспечить атомарность операции. Это повысит надежность кода. Пример:
func (d *DBStorage) InitTables(ctx context.Context) error {
tx, err := d.db.BeginTx(ctx, nil)
if err != nil {
return err
}
defer tx.Rollback()
if _, err := tx.ExecContext(ctx, schemaCounterSQL); err != nil {
return err
}
if _, err := tx.ExecContext(ctx, schemaGaugeSQL); err != nil {
return err
}
return tx.Commit()
}
"golang.org/x/tools/go/types/typeutil" | ||
) | ||
|
||
var ExitOnMainAnalyzer = &analysis.Analyzer{ |
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.
тут хорошо!
"github.com/sirupsen/logrus" | ||
) | ||
|
||
var Logger = logrus.New() |
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.
Рассмотри возможность избавиться от глобальных переменных
И лучше используй zap или zerolog
No description provided.