httplib: add Close() method to shut the server down and use it in tests

This commit is contained in:
Nick Craig-Wood 2018-02-19 14:02:19 +00:00
parent d8f78a7266
commit 334bf49d30
5 changed files with 32 additions and 9 deletions

View file

@ -183,7 +183,15 @@ func (s *Server) Serve() {
} else {
err = s.httpServer.ListenAndServe()
}
log.Fatalf("Fatal error while serving HTTP: %v", err)
log.Printf("Error while serving HTTP: %v", err)
}
// Close shuts the running server down
func (s *Server) Close() {
err := closeServer(s.httpServer)
if err != nil {
log.Printf("Error on closing HTTP server: %v", err)
}
}
// URL returns the serving address of this server