chore(服务端): 初始化工程仓库

This commit is contained in:
leon_mac
2026-10-18 15:11:44 +08:00
commit 13c8bcbf3c
23 changed files with 2543 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
package main
import (
"context"
"log"
"net/http"
"os"
"os/signal"
"perler-beads-server/internal/server"
"syscall"
"time"
)
func main() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
s, e := server.New(ctx)
cancel()
if e != nil {
log.Fatal(e)
}
defer s.DB.Close()
defer s.Redis.Close()
addr := os.Getenv("LISTEN_ADDR")
if addr == "" {
addr = ":8080"
}
h := &http.Server{Addr: addr, Handler: s.Router(), ReadHeaderTimeout: 5 * time.Second, ReadTimeout: 15 * time.Second, WriteTimeout: 30 * time.Second, IdleTimeout: 60 * time.Second}
go func() {
if e := h.ListenAndServe(); e != nil && e != http.ErrServerClosed {
log.Fatal(e)
}
}()
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
ctx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
s.CloseWebSockets()
h.Shutdown(ctx)
}