Files
mtusi2026lab4/backend/pkg/server/server.go
T

30 lines
858 B
Go

package server
import (
"context"
"net/http"
"time"
)
type Server struct {
httpServer *http.Server
}
func New(addr string, handler http.Handler) *Server {
return &Server{httpServer: &http.Server{
Addr: addr,
Handler: handler,
ReadHeaderTimeout: 5 * time.Second,
ReadTimeout: 15 * time.Second,
WriteTimeout: 15 * time.Second,
IdleTimeout: 60 * time.Second,
MaxHeaderBytes: 16 << 10,
}}
}
func (s *Server) ListenAndServe() error { return s.httpServer.ListenAndServe() }
// Shutdown сразу закрывает слушающий сокет (новые соединения не принимаются)
// и ждёт завершения начатых запросов, но не дольше ctx.
func (s *Server) Shutdown(ctx context.Context) error { return s.httpServer.Shutdown(ctx) }