mirror of
https://github.com/3ybactuk/marketplace-go-service-project.git
synced 2025-10-30 14:03:45 +03:00
[hw-8] add: comment service
This commit is contained in:
42
comments/cmd/server/main.go
Normal file
42
comments/cmd/server/main.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"route256/comments/internal/app"
|
||||
)
|
||||
|
||||
func main() {
|
||||
srv, err := app.NewApp(os.Getenv("CONFIG_FILE"))
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("failed creating app")
|
||||
}
|
||||
|
||||
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
||||
defer stop()
|
||||
|
||||
go func() {
|
||||
if err := srv.ListenAndServe(ctx); err != nil && err != http.ErrServerClosed {
|
||||
log.Fatal().Err(err).Msg("serving error")
|
||||
}
|
||||
}()
|
||||
|
||||
<-ctx.Done()
|
||||
log.Info().Msg("shutdown signal received")
|
||||
|
||||
shutdownCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
if err := srv.Shutdown(shutdownCtx); err != nil {
|
||||
log.Error().Err(err).Msg("graceful shutdown failed")
|
||||
} else {
|
||||
log.Info().Msg("server stopped gracefully")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user