cvvvvv/internal/server/server.go

32 lines
639 B
Go

package server
import (
"context"
"net/http"
"git.roboces.dev/catalin/cvvvvv/internal/config"
)
type Server struct {
httpServer *http.Server
}
func NewServer(cfg *config.Config, handler http.Handler) *Server {
return &Server{
httpServer: &http.Server{
Addr: ":" + cfg.HTTP.Port,
Handler: handler,
ReadTimeout: cfg.HTTP.ReadTimeout,
WriteTimeout: cfg.HTTP.WriteTimeout,
MaxHeaderBytes: cfg.HTTP.MaxHeaderMegabytes << 20,
},
}
}
func (s *Server) Run() error {
return s.httpServer.ListenAndServe()
}
func (s *Server) Stop(ctx context.Context) error {
return s.httpServer.Shutdown(ctx)
}