From 8222f53e76095be288b2645b1b25bedf9c30fdd5 Mon Sep 17 00:00:00 2001 From: Peter Deng Date: Wed, 16 Dec 2020 12:56:29 +0800 Subject: [PATCH] check handler func existence before adding it --- libbeat/api/routes.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libbeat/api/routes.go b/libbeat/api/routes.go index c353cada3e4..bc72347cf28 100644 --- a/libbeat/api/routes.go +++ b/libbeat/api/routes.go @@ -81,6 +81,10 @@ func prettyPrint(w http.ResponseWriter, data common.MapStr, u *url.URL) { } // AddHandlerFunc provides interface to add customized handlerFunc -func AddHandlerFunc(api string, h handlerFunc) { +func AddHandlerFunc(api string, h handlerFunc) error { + if _, exist := handlerFuncMap[api]; exist { + return fmt.Errorf("%s already exist", api) + } handlerFuncMap[api] = h + return nil }