package server import ( "log/slog" "net/http" "github.com/eagleusb/proxycon/internal/data" "github.com/eagleusb/proxycon/internal/handlers" "github.com/eagleusb/proxycon/internal/utility" ) // Server holds the HTTP server configuration. type Server struct { handler http.Handler } // NewServer returns a configured HTTP server with all routes registered. func NewServer(p *data.BitcoinPrices, pageSize int) *Server { mux := http.NewServeMux() handlers.Register(mux, p, pageSize) return &Server{ handler: utility.Logger(mux), } } // Listen starts the HTTP server with HTTP/1 and HTTP/2 support. func (s *Server) Listen(addr string) error { srv := &http.Server{ Addr: addr, Handler: s.handler, Protocols: &http.Protocols{}, } srv.Protocols.SetHTTP1(true) srv.Protocols.SetHTTP2(true) srv.Protocols.SetUnencryptedHTTP2(true) slog.Debug("http server protocol", "http1", srv.Protocols.HTTP1(), "http2", srv.Protocols.HTTP2(), "unencrypted", srv.Protocols.UnencryptedHTTP2()) if err := srv.ListenAndServe(); err != nil { return err } return nil }