forked from mtusi2026/mtusi2026lab3
Prepare verified laboratory 3 implementation and evidence
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
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) }
|
||||
Reference in New Issue
Block a user