Skip to content

Commit

Permalink
use default router instead if handler is nil
Browse files Browse the repository at this point in the history
  • Loading branch information
xgfone committed Dec 23, 2024
1 parent 34ab886 commit ebc83ca
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions http/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"net/http"
"time"

"github.com/xgfone/go-apiserver/http/router"
"github.com/xgfone/go-defaults"
)

Expand All @@ -30,7 +31,13 @@ import (
var ServeWithListener func(server *http.Server, ln net.Listener)

// New returns a new http server with the handler.
//
// If handler is nil, use router.DefaultRouter instead.
func New(addr string, handler http.Handler) *http.Server {
if handler == nil {
handler = router.DefaultRouter
}

return &http.Server{
Addr: addr,
Handler: handler,
Expand Down

0 comments on commit ebc83ca

Please sign in to comment.