mirror of
https://github.com/hanzoai/ingress.git
synced 2026-10-26 02:47:15 +00:00
Commits 91 outstanding change(s) that were sitting uncommitted. No build artifacts and no secrets in the changeset (both checked).
86 lines
1.9 KiB
Go
86 lines
1.9 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
// InternalHandlers is the internal HTTP handlers builder.
|
|
type InternalHandlers struct {
|
|
api http.Handler
|
|
dashboard http.Handler
|
|
prometheus http.Handler
|
|
ping http.Handler
|
|
acmeHTTP http.Handler
|
|
}
|
|
|
|
// NewInternalHandlers creates a new InternalHandlers.
|
|
func NewInternalHandlers(apiHandler, metricsHandler, pingHandler, dashboard, acmeHTTP http.Handler) *InternalHandlers {
|
|
return &InternalHandlers{
|
|
api: apiHandler,
|
|
dashboard: dashboard,
|
|
prometheus: metricsHandler,
|
|
ping: pingHandler,
|
|
acmeHTTP: acmeHTTP,
|
|
}
|
|
}
|
|
|
|
// BuildHTTP builds an HTTP handler.
|
|
func (m *InternalHandlers) BuildHTTP(rootCtx context.Context, serviceName string) (http.Handler, error) {
|
|
if !strings.HasSuffix(serviceName, "@internal") {
|
|
return nil, nil
|
|
}
|
|
|
|
internalHandler, err := m.get(serviceName)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return internalHandler, nil
|
|
}
|
|
|
|
func (m *InternalHandlers) get(serviceName string) (http.Handler, error) {
|
|
switch serviceName {
|
|
case "noop@internal":
|
|
return http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) {
|
|
rw.WriteHeader(http.StatusTeapot)
|
|
}), nil
|
|
|
|
case "acme-http@internal":
|
|
if m.acmeHTTP == nil {
|
|
return nil, errors.New("HTTP challenge is not enabled")
|
|
}
|
|
return m.acmeHTTP, nil
|
|
|
|
case "api@internal":
|
|
if m.api == nil {
|
|
return nil, errors.New("api is not enabled")
|
|
}
|
|
return m.api, nil
|
|
|
|
case "dashboard@internal":
|
|
if m.dashboard == nil {
|
|
return nil, errors.New("dashboard is not enabled")
|
|
}
|
|
return m.dashboard, nil
|
|
|
|
case "ping@internal":
|
|
if m.ping == nil {
|
|
return nil, errors.New("ping is not enabled")
|
|
}
|
|
return m.ping, nil
|
|
|
|
case "prometheus@internal":
|
|
if m.prometheus == nil {
|
|
return nil, errors.New("prometheus is not enabled")
|
|
}
|
|
return m.prometheus, nil
|
|
|
|
default:
|
|
return nil, fmt.Errorf("unknown internal service %s", serviceName)
|
|
}
|
|
}
|