app/plugin: add product middleware and enable products register their routers (#20374)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
2580722426
Коммит
c1c084a596
@@ -17,6 +17,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/blang/semver"
|
||||
"github.com/gorilla/mux"
|
||||
svg "github.com/h2non/go-is-svg"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
@@ -37,6 +38,28 @@ type pluginSignaturePath struct {
|
||||
signaturePath string
|
||||
}
|
||||
|
||||
type routerService struct {
|
||||
mu sync.Mutex
|
||||
routerMap map[string]*mux.Router
|
||||
}
|
||||
|
||||
func newRouterService() *routerService {
|
||||
return &routerService{
|
||||
routerMap: make(map[string]*mux.Router),
|
||||
}
|
||||
}
|
||||
|
||||
func (rs *routerService) RegisterRouter(productID string, sub *mux.Router) {
|
||||
rs.mu.Lock()
|
||||
defer rs.mu.Unlock()
|
||||
rs.routerMap[productID] = sub
|
||||
}
|
||||
|
||||
func (rs *routerService) getHandler(productID string) (http.Handler, bool) {
|
||||
handler, ok := rs.routerMap[productID]
|
||||
return handler, ok
|
||||
}
|
||||
|
||||
// GetPluginsEnvironment returns the plugin environment for use if plugins are enabled and
|
||||
// initialized.
|
||||
//
|
||||
|
||||
Ссылка в новой задаче
Block a user