feat: support external api extensions (#852)
This commit is contained in:
parent
1a0932c210
commit
22ed13b9df
2 changed files with 22 additions and 0 deletions
21
hub/route/external.go
Normal file
21
hub/route/external.go
Normal file
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -93,6 +93,7 @@ func Start(addr string, tlsAddr string, secret string,
|
||||||
r.Mount("/dns", dnsRouter())
|
r.Mount("/dns", dnsRouter())
|
||||||
r.Mount("/restart", restartRouter())
|
r.Mount("/restart", restartRouter())
|
||||||
r.Mount("/upgrade", upgradeRouter())
|
r.Mount("/upgrade", upgradeRouter())
|
||||||
|
addExternalRouters(r)
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue