Mirgate project to go

This commit is contained in:
2025-10-02 13:23:09 +02:00
parent d0c2a48238
commit 0e54a6019e
40 changed files with 325 additions and 272 deletions

50
cmd/luxtools/main.go Normal file
View File

@@ -0,0 +1,50 @@
package main
import (
"context"
"errors"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"luxtools/internal/server"
)
func main() {
srv, err := server.New()
if err != nil {
log.Fatalf("failed to configure server: %v", err)
}
httpServer := &http.Server{
Addr: srv.Address(),
Handler: srv.Router(),
ReadTimeout: 15 * time.Second,
WriteTimeout: 15 * time.Second,
IdleTimeout: 60 * time.Second,
}
log.Printf("Luxtools web server running on http://127.0.0.1%s", srv.Address())
go func() {
if err := httpServer.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Fatalf("server error: %v", err)
}
}()
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
<-ctx.Done()
shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := httpServer.Shutdown(shutdownCtx); err != nil {
log.Printf("graceful shutdown failed: %v", err)
} else {
log.Println("server stopped")
}
}