package server import ( "context" "fmt" "net/http" "time" "github.com/neutrino2211/at-rund/internal/atproto" "github.com/neutrino2211/at-rund/internal/config" "github.com/neutrino2211/at-rund/internal/vm" ) type Server struct { cfg *config.Config executor vm.Executor bundleClient *atproto.BundleClient server *http.Server } func New(cfg *config.Config, executor vm.Executor, bundleClient *atproto.BundleClient) *Server { s := &Server{ cfg: cfg, executor: executor, bundleClient: bundleClient, } mux := http.NewServeMux() s.registerRoutes(mux) s.server = &http.Server{ Addr: fmt.Sprintf(":%d", cfg.Port), Handler: mux, ReadTimeout: 30 * time.Second, WriteTimeout: 60 * time.Second, IdleTimeout: 120 * time.Second, } return s } func (s *Server) ListenAndServe() error { return s.server.ListenAndServe() } func (s *Server) Shutdown() error { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() return s.server.Shutdown(ctx) }