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:
parent
910afd6d28
commit
a0e3ab6575
7 changed files with 18 additions and 1 deletions
7
app.go
7
app.go
|
@ -82,6 +82,7 @@ func (s serviceHandlerDocumentationList) Swap(i, j int) { s[i], s[j] = s[j], s[i
|
||||||
|
|
||||||
type serviceHandler interface {
|
type serviceHandler interface {
|
||||||
GetDocumentation() serviceHandlerDocumentationList
|
GetDocumentation() serviceHandlerDocumentationList
|
||||||
|
IsEnabled() bool
|
||||||
Handle(ctx context.Context, params []string) (title, text, color string, err error)
|
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()
|
defer cancel()
|
||||||
|
|
||||||
handler, ok := serviceHandlers[service]
|
handler, ok := serviceHandlers[service]
|
||||||
if !ok {
|
if !ok || !handler.IsEnabled() {
|
||||||
http.Error(res, "Service not found: "+service, http.StatusNotFound)
|
http.Error(res, "Service not found: "+service, http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -242,6 +243,10 @@ func handleDemoPage(res http.ResponseWriter, r *http.Request) {
|
||||||
examples := serviceHandlerDocumentationList{}
|
examples := serviceHandlerDocumentationList{}
|
||||||
|
|
||||||
for register, handler := range serviceHandlers {
|
for register, handler := range serviceHandlers {
|
||||||
|
if !handler.IsEnabled() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
tmps := handler.GetDocumentation()
|
tmps := handler.GetDocumentation()
|
||||||
for _, tmp := range tmps {
|
for _, tmp := range tmps {
|
||||||
tmp.Register = register
|
tmp.Register = register
|
||||||
|
|
|
@ -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) {
|
func (a aurServiceHandler) Handle(ctx context.Context, params []string) (title, text, color string, err error) {
|
||||||
if len(params) < 2 {
|
if len(params) < 2 {
|
||||||
return title, text, color, errors.New("No service-command / parameters were given")
|
return title, text, color, errors.New("No service-command / parameters were given")
|
||||||
|
|
|
@ -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) {
|
func (s beerpayServiceHandler) Handle(ctx context.Context, params []string) (title, text, color string, err error) {
|
||||||
if len(params) < 2 {
|
if len(params) < 2 {
|
||||||
err = errors.New("You need to provide user and project")
|
err = errors.New("You need to provide user and project")
|
||||||
|
|
|
@ -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) {
|
func (g githubServiceHandler) Handle(ctx context.Context, params []string) (title, text, color string, err error) {
|
||||||
if len(params) < 2 {
|
if len(params) < 2 {
|
||||||
err = errors.New("No service-command / parameters were given")
|
err = errors.New("No service-command / parameters were given")
|
||||||
|
|
|
@ -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) {
|
func (s liberapayServiceHandler) Handle(ctx context.Context, params []string) (title, text, color string, err error) {
|
||||||
if len(params) < 2 {
|
if len(params) < 2 {
|
||||||
err = errors.New("You need to provide user and payment direction")
|
err = errors.New("You need to provide user and payment direction")
|
||||||
|
|
|
@ -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) {
|
func (s staticServiceHandler) Handle(ctx context.Context, params []string) (title, text, color string, err error) {
|
||||||
if len(params) < 2 {
|
if len(params) < 2 {
|
||||||
err = errors.New("You need to provide title and text")
|
err = errors.New("You need to provide title and text")
|
||||||
|
|
|
@ -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) {
|
func (t travisServiceHandler) Handle(ctx context.Context, params []string) (title, text, color string, err error) {
|
||||||
if len(params) < 2 {
|
if len(params) < 2 {
|
||||||
err = errors.New("You need to provide user and repo")
|
err = errors.New("You need to provide user and repo")
|
||||||
|
|
Loading…
Reference in a new issue