Minor change to handler type checking to avoid second cast
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Tyler 2021-12-23 00:15:54 -05:00
parent f9f3cec5a2
commit 56df578d6e
1 changed files with 12 additions and 8 deletions

View File

@ -176,19 +176,21 @@ func (s *Server) Start() error {
// StartHTTP is a convenience method to start a basic http server.
// This uses s.forwardHandler if http.Handler is implemented to serve requests.
func (s *Server) StartHTTP(bind string) error {
httpHandler := s.forwardHandlers["http"]
handler := s.forwardHandlers["http"]
if httpHandler == nil {
if handler == nil {
return errors.New("http handler not registered")
}
if _, ok := httpHandler.(http.Handler); !ok {
httpHandler, ok := handler.(http.Handler)
if !ok {
return errors.New("http handler cannot handle http requests")
}
httpServer := &http.Server{
Addr: bind,
Handler: httpHandler.(http.Handler),
Handler: httpHandler,
}
return httpServer.ListenAndServe()
@ -197,15 +199,17 @@ func (s *Server) StartHTTP(bind string) error {
// ServeHTTP is a passthrough to forwardHandler's ServeHTTP
// This can be used to use your own http server implementation, or for TLS/etc
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
httpHandler := s.forwardHandlers["http"]
handler := s.forwardHandlers["http"]
if httpHandler == nil {
if handler == nil {
return
}
if _, ok := httpHandler.(http.Handler); !ok {
httpHandler, ok := handler.(http.Handler)
if !ok {
return
}
httpHandler.(http.Handler).ServeHTTP(w, r)
httpHandler.ServeHTTP(w, r)
}