diff --git a/hub/route/external.go b/hub/route/external.go new file mode 100644 index 00000000..d2f06358 --- /dev/null +++ b/hub/route/external.go @@ -0,0 +1,21 @@ +package route + +import "github.com/go-chi/chi/v5" + +type externalRouter func(r chi.Router) + +var externalRouters = make([]externalRouter, 0) + +func Register(route ...externalRouter) { + externalRouters = append(externalRouters, route...) +} + +func addExternalRouters(r chi.Router) { + if len(externalRouters) == 0 { + return + } + + for _, caller := range externalRouters { + caller(r) + } +} diff --git a/hub/route/server.go b/hub/route/server.go index 6ececddb..0733b310 100644 --- a/hub/route/server.go +++ b/hub/route/server.go @@ -93,6 +93,7 @@ func Start(addr string, tlsAddr string, secret string, r.Mount("/dns", dnsRouter()) r.Mount("/restart", restartRouter()) r.Mount("/upgrade", upgradeRouter()) + addExternalRouters(r) })