Use DefaultServeMux instead of github.com/gorilla/mux

This commit is contained in:
Holger Obermaier 2023-10-11 17:19:39 +02:00
parent b618e81cbb
commit f059d52d43

View File

@ -12,7 +12,6 @@ import (
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger" cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
lp "github.com/ClusterCockpit/cc-metric-collector/pkg/ccMetric" lp "github.com/ClusterCockpit/cc-metric-collector/pkg/ccMetric"
"github.com/gorilla/mux"
influx "github.com/influxdata/line-protocol/v2/lineprotocol" influx "github.com/influxdata/line-protocol/v2/lineprotocol"
) )
@ -39,7 +38,6 @@ type HttpReceiver struct {
receiver receiver
meta map[string]string meta map[string]string
config HttpReceiverConfig config HttpReceiverConfig
router *mux.Router
server *http.Server server *http.Server
wg sync.WaitGroup wg sync.WaitGroup
} }
@ -93,16 +91,16 @@ func (r *HttpReceiver) Init(name string, config json.RawMessage) error {
uri := addr + p uri := addr + p
cclog.ComponentDebug(r.name, "INIT", "listen on:", uri) cclog.ComponentDebug(r.name, "INIT", "listen on:", uri)
// Create new router and register p as path // Register handler function r.ServerHttp for path p in the DefaultServeMux
r.router = mux.NewRouter() http.HandleFunc(p, r.ServerHttp)
r.router.Path(p).HandlerFunc(r.ServerHttp)
// Create http server, with router as handler // Create http server
r.server = &http.Server{ r.server = &http.Server{
Addr: addr, Addr: addr,
Handler: r.router, Handler: nil, // handler to invoke, http.DefaultServeMux if nil
IdleTimeout: r.config.idleTimeout, IdleTimeout: r.config.idleTimeout,
} }
return nil return nil
} }