package server import ( "log/slog" "net" "time" "net/http" "git.mihna123.com/openstore/internal/config" "git.mihna123.com/openstore/internal/server/handlers" ) type Server struct { config *config.Config mux *http.ServeMux } func (s *Server) Serve() error { httpSrv := &http.Server{ Handler: logRequests(s.mux), ReadHeaderTimeout: 5 * time.Second, WriteTimeout: 10 * time.Second, } ln, err := net.Listen("tcp", s.config.Serve.Addr) if err != nil { return err } slog.Info("listening", "name", s.config.Instance.Name, "addr", s.config.Serve.Addr) return httpSrv.Serve(ln) } func New(c *config.Config) *Server { mux := handlers.Routes(c) s := &Server{ config: c, mux: mux, } return s }