app/plugin: add product middleware and enable products register their routers (#20374)

Этот коммит содержится в:
Ibrahim Serdar Acikgoz
2022-06-07 09:12:15 +03:00
коммит произвёл GitHub
родитель 2580722426
Коммит c1c084a596
4 изменённых файлов: 37 добавлений и 1 удалений

Просмотреть файл

@@ -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.
//