2022-04-16 07:28:00 +12:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
2022-04-19 22:14:59 +12:00
|
|
|
"errors"
|
|
|
|
|
2022-04-16 07:28:00 +12:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Plugin interface {
|
2022-04-19 22:14:59 +12:00
|
|
|
Name() string
|
2022-04-16 07:28:00 +12:00
|
|
|
Config() PluginConfig
|
|
|
|
Start(PluginManagers)
|
|
|
|
Shutdown() error
|
|
|
|
}
|
|
|
|
|
2022-04-19 22:14:59 +12:00
|
|
|
type ExposablePlugin interface {
|
|
|
|
Plugin
|
|
|
|
ExposeService() any
|
|
|
|
}
|
|
|
|
|
2022-04-16 07:28:00 +12:00
|
|
|
type PluginConfig interface {
|
|
|
|
Init(cmd *cobra.Command) error
|
|
|
|
Set()
|
|
|
|
}
|
|
|
|
|
|
|
|
type PluginManagers struct {
|
2022-04-19 22:14:59 +12:00
|
|
|
SessionManager SessionManager
|
|
|
|
WebSocketManager WebSocketManager
|
|
|
|
ApiManager ApiManager
|
|
|
|
LoadServiceFromPlugin func(string) (any, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PluginManagers) Validate() error {
|
|
|
|
if p.SessionManager == nil {
|
|
|
|
return errors.New("SessionManager is nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
if p.WebSocketManager == nil {
|
|
|
|
return errors.New("WebSocketManager is nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
if p.ApiManager == nil {
|
|
|
|
return errors.New("ApiManager is nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
if p.LoadServiceFromPlugin == nil {
|
|
|
|
return errors.New("LoadServiceFromPlugin is nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2022-04-16 07:28:00 +12:00
|
|
|
}
|