diff --git a/examples/plugins/traffic-control/main.go b/examples/plugins/traffic-control/main.go index 2f456adf1..f12094e3e 100644 --- a/examples/plugins/traffic-control/main.go +++ b/examples/plugins/traffic-control/main.go @@ -107,8 +107,22 @@ func main() { if err != nil { log.Fatalf("Failed to create a plugin: %v", err) } + + // Cache trafficControlStatusCache = make(map[string]*TrafficControlStatus) - if err := plugin.Serve(listener); err != nil { + + trafficControlServeMux := http.NewServeMux() + + // Report request handler + reportHandler := http.HandlerFunc(plugin.report) + trafficControlServeMux.Handle("/report", reportHandler) + + // Control request handler + controlHandler := http.HandlerFunc(plugin.control) + trafficControlServeMux.Handle("/control", controlHandler) + + log.Println("Listening...") + if err = http.Serve(listener, trafficControlServeMux); err != nil { log.Fatalf("failed to serve: %v", err) } } @@ -157,13 +171,6 @@ func NewPlugin() (*Plugin, error) { return plugin, nil } -// Serve is a wrapper to http.ServeMux to serve the request supported by the plugin -func (p *Plugin) Serve(listener net.Listener) error { - http.HandleFunc("/report", p.report) - http.HandleFunc("/control", p.control) - return http.Serve(listener, nil) -} - func (p *Plugin) report(w http.ResponseWriter, r *http.Request) { raw, err := p.reporter.RawReport() if err != nil {