Files
mtusi2026lab2/app/cmd/server/main.go
T

62 lines
1.0 KiB
Go
Executable File

package main
import (
"context"
"os"
"os/signal"
"syscall"
"time"
"gitflic.ru/project/bulla-max/mtusi2026lab1/internal"
"github.com/gofiber/fiber/v3/log"
)
func main() {
log.SetOutput(os.Stdout)
log.SetLevel(log.LevelDebug)
app := internal.GetApp()
host := os.Getenv("APP_HOST")
port := os.Getenv("APP_PORT")
if port == "" {
port = "8080"
}
if host == "" {
host = "0.0.0.0"
}
addr := host + ":" + port
go func() {
if err := app.Listen(addr); err != nil {
log.Fatalf("Server error: %v", err)
}
}()
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGTERM)
<-quit
ctx, cancel := context.WithTimeout(
context.Background(), 10*time.Second)
defer cancel()
log.Info("Received SIGTERM, shutting down...")
internal.SignalGracefulShutdown()
shutdownComplete := make(chan error, 1)
go func() {
shutdownComplete <- app.Shutdown()
}()
select {
case err := <-shutdownComplete:
log.Errorf("Shutdown error: %v", err)
case <-ctx.Done():
log.Info("Server stopped gracefully")
}
}