3v324v23's picture
init: eino siliconflow demo
32455d6
raw
history blame contribute delete
883 Bytes
package main
import (
"context"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"eino-closedloop-cn/internal/app"
)
func main() {
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
mux := http.NewServeMux()
app.RegisterRoutes(mux)
srv := &http.Server{
Addr: ":" + port,
Handler: mux,
ReadHeaderTimeout: 5 * time.Second,
}
errCh := make(chan error, 1)
go func() {
log.Printf("HTTP 服务已启动:http://localhost:%s", port)
errCh <- srv.ListenAndServe()
}()
stop := make(chan os.Signal, 1)
signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM)
select {
case <-stop:
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
_ = srv.Shutdown(ctx)
case err := <-errCh:
if err != nil && err != http.ErrServerClosed {
log.Fatalf("服务启动失败:%v", err)
}
}
}