update http.Server run
This commit is contained in:
parent
c7dc998670
commit
3514bb9626
15
http.go
15
http.go
@ -451,7 +451,6 @@ func (h *Server) Start() error {
|
|||||||
fn := handler
|
fn := handler
|
||||||
|
|
||||||
var hs *http.Server
|
var hs *http.Server
|
||||||
var srvFunc func(net.Listener) error
|
|
||||||
if h.opts.Context != nil {
|
if h.opts.Context != nil {
|
||||||
if mwf, ok := h.opts.Context.Value(middlewareKey{}).([]func(http.Handler) http.Handler); ok && len(mwf) > 0 {
|
if mwf, ok := h.opts.Context.Value(middlewareKey{}).([]func(http.Handler) http.Handler); ok && len(mwf) > 0 {
|
||||||
// wrap the handler func
|
// wrap the handler func
|
||||||
@ -462,24 +461,16 @@ func (h *Server) Start() error {
|
|||||||
var ok bool
|
var ok bool
|
||||||
if hs, ok = h.opts.Context.Value(serverKey{}).(*http.Server); ok && hs != nil {
|
if hs, ok = h.opts.Context.Value(serverKey{}).(*http.Server); ok && hs != nil {
|
||||||
hs.Handler = fn
|
hs.Handler = fn
|
||||||
srvFunc = hs.Serve
|
} else {
|
||||||
|
hs = &http.Server{Handler: fn}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if srvFunc != nil {
|
|
||||||
go func() {
|
go func() {
|
||||||
if cerr := srvFunc(ts); cerr != nil && !errors.Is(cerr, net.ErrClosed) {
|
|
||||||
h.opts.Logger.Error(h.opts.Context, "failed to serve", cerr)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
} else {
|
|
||||||
go func() {
|
|
||||||
hs = &http.Server{Handler: fn}
|
|
||||||
if cerr := hs.Serve(ts); cerr != nil && !errors.Is(cerr, net.ErrClosed) {
|
if cerr := hs.Serve(ts); cerr != nil && !errors.Is(cerr, net.ErrClosed) {
|
||||||
h.opts.Logger.Error(h.opts.Context, "failed to serve", cerr)
|
h.opts.Logger.Error(h.opts.Context, cerr)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
t := new(time.Ticker)
|
t := new(time.Ticker)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user