feat: support external api extensions (#852)

This commit is contained in:
snakem982 2023-12-03 09:39:34 +08:00 committed by GitHub
parent 1a0932c210
commit 22ed13b9df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

21
hub/route/external.go Normal file
View 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)
}
}

View file

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