safeweb: add a ListenAndServe method to the Server type (#13498)

Updates #13497

Change-Id: I398e9fa58ad0b9dc799ea280c9c7a32150150ee4
Signed-off-by: M. J. Fromberger <fromberger@tailscale.com>
This commit is contained in:
M. J. Fromberger 2024-09-17 12:59:28 -07:00 committed by GitHub
parent 951884b077
commit 5f89c93274
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 0 deletions

View File

@ -301,6 +301,19 @@ func (s *Server) Serve(ln net.Listener) error {
return s.h.Serve(ln)
}
// ListenAndServe listens on the TCP network address addr and then calls Serve
// to handle requests on incoming connections. If addr == "", ":http" is used.
func (s *Server) ListenAndServe(addr string) error {
if addr == "" {
addr = ":http"
}
lst, err := net.Listen("tcp", addr)
if err != nil {
return err
}
return s.Serve(lst)
}
// Close closes all client connections and stops accepting new ones.
func (s *Server) Close() error {
return s.h.Close()