jobs-monorepo/internal/server/server.go
Elshimy Ziad Magdy Taha 7bf35ccb6b refactor
2025-09-29 22:44:30 +05:00

40 lines
666 B
Go

package server
import (
"context"
http "net/http"
"time"
"github.com/gorilla/mux"
)
type AppServer struct {
router *mux.Router
httpServer *http.Server
}
func NewServer(router *mux.Router) *AppServer {
port := "8080"
httpServer := &http.Server{
Addr: ":" + port,
Handler: router,
ReadTimeout: 15 * time.Second,
WriteTimeout: 15 * time.Second,
IdleTimeout: 60 * time.Second,
}
server := &AppServer{
router: router,
httpServer: httpServer,
}
return server
}
func (s *AppServer) Start() error {
return s.httpServer.ListenAndServe()
}
func (s *AppServer) Stop(ctx context.Context) {
s.httpServer.Shutdown(ctx)
}