41 lines
807 B
Go
41 lines
807 B
Go
package module
|
|
|
|
import (
|
|
"forge.cadoles.com/arcad/edge/pkg/app"
|
|
"github.com/dop251/goja"
|
|
)
|
|
|
|
type ExtensionFunc func(*goja.Object)
|
|
|
|
type ExtendedModule struct {
|
|
module app.ServerModule
|
|
extensions []ExtensionFunc
|
|
}
|
|
|
|
// Export implements app.ServerModule.
|
|
func (m *ExtendedModule) Export(exports *goja.Object) {
|
|
m.module.Export(exports)
|
|
|
|
for _, ext := range m.extensions {
|
|
ext(exports)
|
|
}
|
|
}
|
|
|
|
// Name implements app.ServerModule.
|
|
func (m *ExtendedModule) Name() string {
|
|
return m.module.Name()
|
|
}
|
|
|
|
func Extends(factory app.ServerModuleFactory, extensions ...ExtensionFunc) app.ServerModuleFactory {
|
|
return func(s *app.Server) app.ServerModule {
|
|
module := factory(s)
|
|
|
|
return &ExtendedModule{
|
|
module: module,
|
|
extensions: extensions,
|
|
}
|
|
}
|
|
}
|
|
|
|
var _ app.ServerModule = &ExtendedModule{}
|