From a0e3ab6575f630fc944173e8256b326f9d9f92b1 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Thu, 11 Mar 2021 11:16:15 +0100 Subject: [PATCH] Allow service handler to disable itself Signed-off-by: Knut Ahlers --- app.go | 7 ++++++- service_aur.go | 2 ++ service_beerpay.go | 2 ++ service_github.go | 2 ++ service_liberapay.go | 2 ++ service_static.go | 2 ++ service_travis.go | 2 ++ 7 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app.go b/app.go index f3c7b1b..0ef08fc 100644 --- a/app.go +++ b/app.go @@ -82,6 +82,7 @@ func (s serviceHandlerDocumentationList) Swap(i, j int) { s[i], s[j] = s[j], s[i type serviceHandler interface { GetDocumentation() serviceHandlerDocumentationList + IsEnabled() bool Handle(ctx context.Context, params []string) (title, text, color string, err error) } @@ -142,7 +143,7 @@ func generateServiceBadge(res http.ResponseWriter, r *http.Request) { defer cancel() handler, ok := serviceHandlers[service] - if !ok { + if !ok || !handler.IsEnabled() { http.Error(res, "Service not found: "+service, http.StatusNotFound) return } @@ -242,6 +243,10 @@ func handleDemoPage(res http.ResponseWriter, r *http.Request) { examples := serviceHandlerDocumentationList{} for register, handler := range serviceHandlers { + if !handler.IsEnabled() { + continue + } + tmps := handler.GetDocumentation() for _, tmp := range tmps { tmp.Register = register diff --git a/service_aur.go b/service_aur.go index be5be7b..7b13594 100644 --- a/service_aur.go +++ b/service_aur.go @@ -69,6 +69,8 @@ func (a aurServiceHandler) GetDocumentation() serviceHandlerDocumentationList { } } +func (aurServiceHandler) IsEnabled() bool { return true } + func (a aurServiceHandler) Handle(ctx context.Context, params []string) (title, text, color string, err error) { if len(params) < 2 { return title, text, color, errors.New("No service-command / parameters were given") diff --git a/service_beerpay.go b/service_beerpay.go index dc337f0..c04d668 100644 --- a/service_beerpay.go +++ b/service_beerpay.go @@ -24,6 +24,8 @@ func (s beerpayServiceHandler) GetDocumentation() serviceHandlerDocumentationLis }} } +func (beerpayServiceHandler) IsEnabled() bool { return true } + func (s beerpayServiceHandler) Handle(ctx context.Context, params []string) (title, text, color string, err error) { if len(params) < 2 { err = errors.New("You need to provide user and project") diff --git a/service_github.go b/service_github.go index 438100f..ecf4a92 100644 --- a/service_github.go +++ b/service_github.go @@ -71,6 +71,8 @@ func (g githubServiceHandler) GetDocumentation() serviceHandlerDocumentationList } } +func (githubServiceHandler) IsEnabled() bool { return true } + func (g githubServiceHandler) Handle(ctx context.Context, params []string) (title, text, color string, err error) { if len(params) < 2 { err = errors.New("No service-command / parameters were given") diff --git a/service_liberapay.go b/service_liberapay.go index b531807..02a129b 100644 --- a/service_liberapay.go +++ b/service_liberapay.go @@ -44,6 +44,8 @@ func (s liberapayServiceHandler) GetDocumentation() serviceHandlerDocumentationL } } +func (liberapayServiceHandler) IsEnabled() bool { return true } + func (s liberapayServiceHandler) Handle(ctx context.Context, params []string) (title, text, color string, err error) { if len(params) < 2 { err = errors.New("You need to provide user and payment direction") diff --git a/service_static.go b/service_static.go index 0ba1e90..69386c3 100644 --- a/service_static.go +++ b/service_static.go @@ -20,6 +20,8 @@ func (s staticServiceHandler) GetDocumentation() serviceHandlerDocumentationList }} } +func (staticServiceHandler) IsEnabled() bool { return true } + func (s staticServiceHandler) Handle(ctx context.Context, params []string) (title, text, color string, err error) { if len(params) < 2 { err = errors.New("You need to provide title and text") diff --git a/service_travis.go b/service_travis.go index 7816b7b..362485a 100644 --- a/service_travis.go +++ b/service_travis.go @@ -24,6 +24,8 @@ func (t travisServiceHandler) GetDocumentation() serviceHandlerDocumentationList }} } +func (travisServiceHandler) IsEnabled() bool { return true } + func (t travisServiceHandler) Handle(ctx context.Context, params []string) (title, text, color string, err error) { if len(params) < 2 { err = errors.New("You need to provide user and repo")