package main import ( "context" "errors" "log/slog" "net/http" "os" "os/signal" "syscall" "time" "git.sendico.io/tech/sxchnge/bff/internal/httpapi" ) func main() { if err := run(); err != nil { slog.Error("BFF stopped", "error", err) os.Exit(1) } } func run() error { addr := os.Getenv("SXCHNGE_HTTP_ADDR") if addr == "" { addr = "127.0.0.1:8082" } server := &http.Server{Addr: addr, Handler: httpapi.New(), ReadHeaderTimeout: 5 * time.Second, ReadTimeout: 15 * time.Second, WriteTimeout: 15 * time.Second, IdleTimeout: 60 * time.Second, MaxHeaderBytes: 1 << 20} ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) defer stop() failures := make(chan error, 1) go func() { failures <- server.ListenAndServe() }() slog.Info("BFF operational shell starting", "address", addr, "provider_configured", false) select { case err := <-failures: if errors.Is(err, http.ErrServerClosed) { return nil } return err case <-ctx.Done(): shutdown, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() slog.Info("BFF shutting down") return server.Shutdown(shutdown) } }