Skip to content

Commit

Permalink
pkg/server/http: Allow passing http.ServeMux with a server option (#3769
Browse files Browse the repository at this point in the history
)

Signed-off-by: Matthias Loibl <[email protected]>
  • Loading branch information
metalmatze authored Feb 8, 2021
1 parent 42888ab commit ad2a53c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/server/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func New(logger log.Logger, reg *prometheus.Registry, comp component.Component,
}

mux := http.NewServeMux()
if options.mux != nil {
mux = options.mux
}

registerMetrics(mux, reg)
registerProbes(mux, prober, logger)
registerProfiler(mux)
Expand Down
9 changes: 9 additions & 0 deletions pkg/server/http/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
package http

import (
"net/http"
"time"
)

type options struct {
gracePeriod time.Duration
listen string
mux *http.ServeMux
}

// Option overrides behavior of Server.
Expand Down Expand Up @@ -38,3 +40,10 @@ func WithListen(s string) Option {
o.listen = s
})
}

// WithMux overrides the the server's default mux.
func WithMux(mux *http.ServeMux) Option {
return optionFunc(func(o *options) {
o.mux = mux
})
}

0 comments on commit ad2a53c

Please sign in to comment.