edge/pkg/module/lifecycle.go

48 lines
905 B
Go
Raw Permalink Normal View History

2023-02-09 12:16:36 +01:00
package module
import (
"context"
"forge.cadoles.com/arcad/edge/pkg/app"
"github.com/dop251/goja"
"github.com/pkg/errors"
"gitlab.com/wpetit/goweb/logger"
)
type LifecycleModule struct {
server *app.Server
}
func (m *LifecycleModule) Name() string {
return "lifecycle"
}
func (m *LifecycleModule) Export(export *goja.Object) {
}
func (m *LifecycleModule) OnInit() error {
if _, err := m.server.ExecFuncByName("onInit"); err != nil {
if errors.Is(err, app.ErrFuncDoesNotExist) {
logger.Warn(context.Background(), "could not find onInit() function", logger.E(errors.WithStack(err)))
return nil
}
return errors.WithStack(err)
}
return nil
}
func LifecycleModuleFactory() app.ServerModuleFactory {
2023-02-09 12:16:36 +01:00
return func(server *app.Server) app.ServerModule {
module := &LifecycleModule{
server: server,
}
return module
}
}
var _ app.InitializableModule = &LifecycleModule{}