From 7129f6c1c00103a403717a68a0d91965b818db5b Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Mon, 4 Nov 2019 12:53:14 -0700 Subject: [PATCH] admin: Remove /unload endpoint (is same as DELETE /config/) --- admin.go | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/admin.go b/admin.go index fb7b34b6..502a968c 100644 --- a/admin.go +++ b/admin.go @@ -90,7 +90,6 @@ func (admin AdminConfig) newAdminHandler(listenAddr string) adminHandler { addRoute("/load", AdminHandlerFunc(handleLoad)) addRoute("/"+rawConfigKey+"/", AdminHandlerFunc(handleConfig)) addRoute("/id/", AdminHandlerFunc(handleConfigID)) - addRoute("/unload", AdminHandlerFunc(handleUnload)) addRoute("/stop", AdminHandlerFunc(handleStop)) // register debugging endpoints @@ -543,6 +542,21 @@ func handleConfigID(w http.ResponseWriter, r *http.Request) error { return ErrInternalRedir } +func handleStop(w http.ResponseWriter, r *http.Request) error { + defer func() { + Log().Named("admin.api").Info("stopping now, bye!! 👋") + os.Exit(0) + }() + err := handleUnload(w, r) + if err != nil { + Log().Named("admin.api").Error("unload error", zap.Error(err)) + } + return nil +} + +// handleUnload stops the current configuration that is running. +// Note that doing this can also be accomplished with DELETE /config/ +// but we leave this function because handleStop uses it. func handleUnload(w http.ResponseWriter, r *http.Request) error { if r.Method != http.MethodPost { return APIError{ @@ -566,18 +580,6 @@ func handleUnload(w http.ResponseWriter, r *http.Request) error { return nil } -func handleStop(w http.ResponseWriter, r *http.Request) error { - defer func() { - Log().Named("admin.api").Info("stopping now, bye!! 👋") - os.Exit(0) - }() - err := handleUnload(w, r) - if err != nil { - Log().Named("admin.api").Error("unload error", zap.Error(err)) - } - return nil -} - // unsyncedConfigAccess traverses into the current config and performs // the operation at path according to method, using body and out as // needed. This is a low-level, unsynchronized function; most callers