add application run and stop

This commit is contained in:
yash 2024-01-25 15:44:38 +03:00
parent 29686ee798
commit bad50a81cc
4 changed files with 6 additions and 3 deletions

View File

@ -65,7 +65,7 @@ func New(log *slog.Logger, cfg *config.HTTPServerConfig, storage Storage, mediaS
func (app *App) MustRun() { func (app *App) MustRun() {
const op = "app.httpSrv.Stop" const op = "app.httpSrv.Stop"
if err := app.srv.ListenAndServe(); err != nil && err != http.ErrServerClosed { if err := app.srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
app.log.Error("failed to start server", sl.Err(err)) app.log.Error("failed to start server", slog.String("op", op), sl.Err(err))
panic(err) panic(err)
} }
app.log.Info("HTTP server stopped") app.log.Info("HTTP server stopped")
@ -76,7 +76,7 @@ func (app *App) Stop() {
shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 30*time.Second) shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 30*time.Second)
err := app.srv.Shutdown(shutdownCtx) err := app.srv.Shutdown(shutdownCtx)
if err != nil { if err != nil {
app.log.Error("failed to stop server", sl.Err(err)) app.log.Error("failed to stop server", slog.String("op", op), sl.Err(err))
} }
shutdownCancel() shutdownCancel()
} }

View File

@ -44,6 +44,7 @@ func New(log *slog.Logger, imageProvider ImageProvider) http.HandlerFunc {
err = renderObject(w, r, obj) err = renderObject(w, r, obj)
if err != nil { if err != nil {
log.Error("Fail on rendering object", sl.Err(err)) log.Error("Fail on rendering object", sl.Err(err))
render.JSON(w, r, resp.Error("cannot get file"))
} }
} }
} }

View File

@ -57,6 +57,8 @@ func (o *ObjStorage) getFile(ctx context.Context, bucketName string, objectName
} }
// Delete file from bucket // Delete file from bucket
//
//nolint:unused
func (o *ObjStorage) delFile(ctx context.Context, bucketName string, objectName string) error { func (o *ObjStorage) delFile(ctx context.Context, bucketName string, objectName string) error {
const op = "media_storage.minio.DelFile" const op = "media_storage.minio.DelFile"
err := o.minio.RemoveObject(ctx, bucketName, objectName, minio.RemoveObjectOptions{ForceDelete: true}) err := o.minio.RemoveObject(ctx, bucketName, objectName, minio.RemoveObjectOptions{ForceDelete: true})

View File

@ -38,7 +38,7 @@ func (s *Storage) AddRecipe(ctx context.Context, recipe models.Recipe) error {
// refactor error handling // refactor error handling
// rollback transaction on return // rollback transaction on return
defer tx.Rollback(ctx) defer tx.Rollback(ctx) //nolint:errcheck
var id uint var id uint
// insert recipe // insert recipe