1
0
Fork 0
mirror of https://github.com/Luzifer/badge-gen.git synced 2024-11-09 13:50:03 +00:00

Allow service handler to disable itself

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2021-03-11 11:16:15 +01:00
parent 910afd6d28
commit a0e3ab6575
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D
7 changed files with 18 additions and 1 deletions

7
app.go
View file

@ -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

View file

@ -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")

View file

@ -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")

View file

@ -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")

View file

@ -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")

View file

@ -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")

View file

@ -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")